package com.health.viewscontrols.settings;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.UiMessageUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import com.health.httpbean.HttpConstant;
import com.health.httpbean.HttpDataBean;
import com.health.httpbean.HttpNewConstant;
import com.health.httpbean.HttpResultBean;
import com.health.httpbean.HttpResultStrBean;
import com.health.httpbean.QueryTypeEnum;
import com.health.httpbean.format.ArchiveFormatData;
import com.health.httpbean.format.FormatFjhData;
import com.health.httpbean.format.FormatGxbData;
import com.health.httpbean.format.FormatGxyData;
import com.health.httpbean.format.FormatJsbData;
import com.health.httpbean.format.FormatTnbData;
import com.health.httpbean.model.BpModel;
import com.health.httpbean.model.EcgModel;
import com.health.httpbean.model.MeasureBean;
import com.health.httpbean.model.PoModel;
import com.health.httpbean.model.UeModel;
import com.health.httpbean.upload.ArchiveUpload;
import com.health.httpbean.upload.FjhUpload;
import com.health.httpbean.upload.GxbUpload;
import com.health.httpbean.upload.GxyUpload;
import com.health.httpbean.upload.JsbUpload;
import com.health.httpbean.upload.TnbUpload;
import com.health.model.LvYueFuWuBean;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_DIABETESFOLLOWUP;
import com.health.tablebean.CD_HYPERTENSIONFOLLOWUP;
import com.health.tablebean.CD_MENTALDISEASE_FOLLOWUP;
import com.health.tablebean.CD_TUBERCULOSIS_FOLLOWUP;
import com.health.tablebean.JTYS_SignPictureData;
import com.health.tablebean.SBCL_DATA;
import com.health.tablebean.SBCL_DATA_NEW;
import com.health.tablebean.webservice.CoronaryHeartDisease;
import com.health.tablebean.webservice.FeiXinBing;
import com.health.tablebean.webservice.FengShiBing;
import com.health.tablebean.webservice.HdDiseaseManageStroke;
import com.health.tablebean.webservice.LeiFengShi;
import com.health.tablebean.webservice.ManZuFei;
import com.health.tablebean.webservice.MeasurementDataNew;
import com.health.tablebean.webservice.QyinfoUploadBean;
import com.health.tablebean.webservice.TuberculosisBaseInfo;
import com.health.tablebean.webservice.TuberculosisFollowUpInfo;
import com.health.tools.AssetUtil;
import com.health.tools.ImageTools;
import com.health.tools.JianKangXiaoZhanURl;
import com.health.viewscontrols.NovaActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.R;
import com.health.adapter.UPDataMenuGridAdapter;
import com.health.db.FDbManager;
import com.health.model.UpDataReturn;

import com.health.tablebean.JTYSCustomerDoctorCont;
import com.health.tablebean.JTYSDoctorEvaluateBean;
import com.health.tablebean.JTYS_BASEINFO;
import com.health.tablebean.webservice.ChildWithOneYearOld;
import com.health.tablebean.webservice.ChildhealthNeonate;
import com.health.tablebean.webservice.Diabetes;
import com.health.tablebean.webservice.FirstPrenatalVisit;
import com.health.tablebean.webservice.HdPersonalInfo;
import com.health.tablebean.webservice.HealthCheck;
import com.health.tablebean.webservice.Hypertensio;
import com.health.tablebean.webservice.JsjbBaseInfo;
import com.health.tablebean.webservice.Jsjbsfb;
import com.health.tablebean.webservice.MaternalFortyTwoDaysVisits;
import com.health.tablebean.webservice.MaternalPostnatalVisits;
import com.health.tablebean.webservice.MeasurementData;
import com.health.tablebean.webservice.MonthsChildHomeVisit;
import com.health.tablebean.webservice.OldPhysique;
import com.health.tablebean.webservice.OldSelfHelp;
import com.health.tablebean.webservice.SecondToFifthPrenatalVisits;
import com.health.tablebean.webservice.YearChildHomeVisit;
import com.health.tools.GetPostJTYS;
import com.health.tools.GlobalConts;
import com.health.tools.GlobalContsJTYS;
import com.health.tools.JX_SJSC;
import com.health.tools.JX_UploadData;
import com.health.tools.ModuleName;
import com.health.tools.ResultTextDialog;
import com.health.tools.SPUtil;
import com.health.tools.UploadDataBean;
import com.health.tools.UploadDatas;
import com.health.viewscontrols.NovaPtActivity;
import com.health.webservices.ZCMWebService;
import com.novabluetooth.views.twj.PwBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import rxhttp.RxHttp;

/**
 * 数据上传
 */
public class DataDownLoadMainActivity extends NovaPtActivity implements OnClickListener, UiMessageUtils.UiMessageCallback {

    private static final String TAG = "DataDownLoadMainActivit";

    private static final int DOWNLOAD_OVER = 1;
    private static final int UPLOAD_FWMYD = 2;
    private static final int NO_DATA = 3;
    private static final int SHOW_UPLOAD_RESULT = 4;
    private static final int UPLOAD_FUMYD2 = 5;
    private static final int UPDATA_TNB = 8;
    private static final int UPDATA_GXY = 9;
    protected static final int UPDATA_JKTJ = 10;
    protected static final int UPDATA_OLDZY = 11;
    protected static final int UPDATA_OLDZL = 12;
    protected static final int UPLOAD_MEASUREMENT_DATA = 13;
    protected static final String TYPE_FWXMB = "TYPE_FWXMB";
    protected static final String TYPE_JTQYYH = "TYPE_JTQYYH";
    public static final String TYPE_FWMYDPJ = "TYPE_FWMYDPJ";
    public static final String TYPE_CJYH = "TYPE_CJYH";
    private TextView title;
    private Button btn_back;
    private Button btn_up;
    static FDbManager fdbmanager = null;
    private int sumSize = 0;
    private int successCount = 0;
    private int failCount = 0;
    private int sumSize0 = 0;
    private int successCount0 = 0;
    private int failCount0 = 0;
    private String errorMsg0 = "";
    private int failCountYcz0 = 0;
    private int sumSize1 = 0;
    private int successCount1 = 0;
    private int failCount1 = 0;
    private int sumSize2 = 0;
    private int successCount2 = 0;
    private int failCount2 = 0;
    private int sumSize3 = 0;
    private int successCount3 = 0;
    private int failCount3 = 0;
    boolean isWorking = true;
    private ResultTextDialog resultDialog;
    private GridView gd_menu1;
    private ImageView img_photo1;
    private TextView tv_name1;
    List<HdPersonalInfo> convertDataInfo;//个人基本信息
    List<Diabetes> convertDataTnb;//糖尿病
    /**
     * 肺结核第一次入户随访上传接口参数（基本信息）
     */
    List<TuberculosisBaseInfo> convertDataFjhBaseInfo;
    /**
     * 肺结核随访上传接口参数（随访信息）
     */
    List<TuberculosisFollowUpInfo> convertDataFjhFollowUpInfo;
    List<Hypertensio> convertDataGxy;//高血压
    List<CoronaryHeartDisease> convertDataGXB;//冠心病
    List<HdDiseaseManageStroke> convertDataNCZ;//脑卒中
    List<HealthCheck> convertDataJktj;//健康体检
    List<OldPhysique> convertDataLnrzyy;//老年人中医药
    List<OldSelfHelp> convertDataLnrzlnl;//老年人自理能力
//    List<JTYSCustomerDoctorCont> conts;//签约用户
    List<QyinfoUploadBean> contsQyyh;//签约用户

    List<JTYSDoctorEvaluateBean> evaluates;//用户满意度
    List<ChildhealthNeonate> convertDataXSRFS;//新生儿访视
    List<ChildWithOneYearOld> convertDataOneMonth;//满月内检查
    List<ChildWithOneYearOld> convertDataThreeMonth;//三月龄
    List<ChildWithOneYearOld> convertDataSixMonth;//六月龄
    List<ChildWithOneYearOld> convertData8Month;//八月龄
    List<JsjbBaseInfo> converJsjbInfo;//严重精神病基本信息
    List<Jsjbsfb> converJsjbsfb;//严重精神病随访
    List<JTYS_SignPictureData> pictures;//照片
    List<LvYueFuWuBean> lvYueFuWuBeans;//履约服务

    List<FeiXinBing> feiXinBingFollowups;//肺心病
    List<LeiFengShi> leiFengShiFollowups;//类风湿
    List<ManZuFei> manZuFeiFollowups;//慢阻肺
    List<FengShiBing> fengShiBingFollowups;//风湿病
    /**
     * 12月龄儿童家庭访视
     */
    List<MonthsChildHomeVisit> convertData12Month;
    /**
     * 18月龄儿童家庭访视
     */
    List<MonthsChildHomeVisit> convertData18Month;
    /**
     * 24月龄儿童家庭访视
     */
    List<MonthsChildHomeVisit> convertData24Month;
    /**
     * 30月龄儿童家庭访视
     */
    List<MonthsChildHomeVisit> convertData30Month;
    /**
     * 三岁儿童家庭访视
     */
    List<YearChildHomeVisit> convertData3Year;
    /**
     * 四岁儿童家庭访视
     */
    List<YearChildHomeVisit> convertData4Year;
    /**
     * 五岁儿童家庭访视
     */
    List<YearChildHomeVisit> convertData5Year;
    /**
     * 六岁儿童家庭访视
     */
    List<YearChildHomeVisit> convertData6Year;
    /**
     * 第一次产前访视
     */
    List<FirstPrenatalVisit> convertDataTheFirstTimePrenatalVisit;
    /**
     * 第2次产前随访
     */
    List<SecondToFifthPrenatalVisits> convertData2TimesPrenatalVisits;
    /**
     * 第3次产前随访
     */
    List<SecondToFifthPrenatalVisits> convertData3TimesPrenatalVisits;
    /**
     * 第4次产前随访
     */
    List<SecondToFifthPrenatalVisits> convertData4TimesPrenatalVisits;
    /**
     * 第5次产前随访
     */
    List<SecondToFifthPrenatalVisits> convertData5TimesPrenatalVisits;
    /**
     * 孕产妇产后访视
     */
    List<MaternalPostnatalVisits> convertDataMaternalPostnatalVisits;
    /**
     * 孕产妇产后42天健康检查
     */
    List<MaternalFortyTwoDaysVisits> convertDataMaternalFortyTwoDaysVisits;

    /**
     * 设置截取长度【分批数据上传】
     */
    private static final int subSize = 10;
    private int count = 0;//标识上传次数

    public int xiaozhanCount = 0;//健康小站血压上传次数
    List<SBCL_DATA> xiaoZhanData;//血压数据
    public int xueTangCount=0;//健康小站血糖上传次数
    List<SBCL_DATA> xueTangData;//血糖数据
    private LinearLayout ll_finish;
    private TextView tv_title;
    private Gson mGson = new Gson();
    private List<Object> objectList;
    private List<ARCHIVE_BASEINFO> archiveBaseinfos;
    private List<ARCHIVE_BASEINFO> archiveBaseinfosNew;
    private List<SBCL_DATA_NEW> sbclDataNewList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jkjy_main_content_modify);
        fdbmanager = NovaApplication.fdbmanger;
        findViews();
        addListeners();
    }

    @Override
    public void findViews() {
        title = (TextView) findViewById(R.id.title);
        title.setText("同步数据");


        btn_back = (Button) findViewById(R.id.btn_back);


        findViewById(R.id.bt_save).setVisibility(View.GONE);
        TextView tv_goweb = (TextView)findViewById(R.id.tv_goweb);
        tv_goweb.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(DataDownLoadMainActivity.this,GoWebActivity.class);
                startActivity(intent);
            }
        });
        ll_finish = (LinearLayout)findViewById(R.id.ll_finish);
        tv_title = (TextView)findViewById(R.id.tv_title);

        btn_up = (Button) findViewById(R.id.btn_up);
        btn_up.setVisibility(View.GONE);

        gd_menu1 = (GridView) findViewById(R.id.gd_menu1);
        UPDataMenuGridAdapter menuAdapter1 = new UPDataMenuGridAdapter(this, GlobalContsJTYS.MENU_UPLOAD);
        gd_menu1.setAdapter(menuAdapter1);
        img_photo1 = (ImageView) findViewById(R.id.img_photo1);
        img_photo1.setImageResource(R.drawable.upload_s);
        tv_name1 = (TextView) findViewById(R.id.tv_name1);
        tv_name1.setText("数据上传");
        tv_title.setText("数据上传");
        ll_finish.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
    /**
     * 同步健康小站血压
     */
    public void tongBuJKXZYH(List<SBCL_DATA> list) {
        xiaozhanCount = 0;
        xiaoZhanData = list;
        if (xiaozhanCount <= list.size() - 1) {
            showProgressDialog("血压正在上传，请稍候");
            isZhuCe(xiaozhanCount, list,"xueya");
        }


    }

    /**
     * 同步健康小站血糖
     */
    public void tongBuXueTang(List<SBCL_DATA> list){
        xueTangCount=0;
        xueTangData=list;
        if(xueTangCount<=xueTangData.size()-1){
            showProgressDialog("血糖正在上传，请稍候");
            isZhuCe(xueTangCount, list,"xuetang");
        }
    }

    Handler mHandler1 = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what==0){
                if (xiaozhanCount <= xiaoZhanData.size() - 1) {
                    isZhuCe(xiaozhanCount, xiaoZhanData,"xueya");
                }else{
                    cancelProgressDialog();
                    showTextDialog(xiaozhanCount+"条血压数据上传成功");
                    if(xueTangCount<=xueTangData.size()-1){
                        tongBuXueTang(xueTangData);
                    }else{
                        showTextDialog("无数据可上传");
                    }
                }
            }else if(msg.what==1){
                if(xueTangCount<=xueTangData.size()-1){
                    isZhuCe(xueTangCount,xueTangData,"xuetang");
                }else{
                    cancelProgressDialog();
                    showTextDialog(xueTangCount+"条血糖数据上传成功");
                }
            }

        }
    };

    /**
     * 验证用户是否已在健康小站注册
     */
    public void isZhuCe(int count, List<SBCL_DATA> list,final String type) {

        OkHttpClient client = new OkHttpClient();
        String parms = "?cardNum=" + list.get(count).getIDCARD() + "&loginType=1&deviceId=" + GlobalConts.generateIMEI(getApplicationContext());

        Request request = new Request.Builder().url(JianKangXiaoZhanURl.LOGIN + parms).build();
        Log.e("返回值", "----->get" + JianKangXiaoZhanURl.LOGIN + parms);
        //Call 将你的请求封装成任务
        Call call = client.newCall(request);
        //请求调度
        call.enqueue(new Callback() {
            //失败
            @Override
            public void onFailure(Call call, IOException e) {

            }

            //成功
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //返回String
                String json = response.body().string();
                Log.e("返回值", "----->get" + json);
                try {
                    JSONObject js = new JSONObject(json);
                    JSONArray jsonArray = js.getJSONArray("inforList");
                    Log.e("返回值", "----->get" + jsonArray.length());
                    if ("0".equals(js.getString("respCode"))) {
                        if (jsonArray.length() == 0) {
                            //注册用户
                            if("xueya".equals(type)){
                                register(xiaozhanCount, xiaoZhanData,"xueya");
                            }else if("xuetang".equals(type)){
                                register(xueTangCount, xueTangData,"xuetang");
                            }

                        } else {
                            JSONObject bean = jsonArray.getJSONObject(0);
                            String id = bean.getString("id");
                            //上传血压
                            if("xueya".equals(type)){
                                updateXueYa(id, xiaoZhanData.get(xiaozhanCount));
                            }else if("xuetang".equals(type)){
                                updateXueTang(id,xueTangData.get(xueTangCount));
                            }


                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    /**
     * 注册健康小站用户
     */
    public void register(int count, List<SBCL_DATA> list,final String type) {
        List<ARCHIVE_BASEINFO> baseinfos = fdbmanager.findAllByWhere(ARCHIVE_BASEINFO.class, "IDCARD=" + list.get(count).getIDCARD());

        if (baseinfos.size() > 0) {
            OkHttpClient client = new OkHttpClient();
            String sex = "0";
            if ("DM01-08_1".equals(baseinfos.get(0).getSEX())) {
                sex = "1";
            } else {
                sex = "2";
            }
            String parms = "?cardNum=" + list.get(count).getIDCARD() + "&cardType=1&deviceId=" + GlobalConts.generateIMEI(getApplicationContext()) + "&name=" + baseinfos.get(0).getCUSTOMERNAME() + "&sex=" + sex + "&address=" + baseinfos.get(0).getHOUSEHOLD_ADDR().replaceAll("#","%23").replaceAll("&","%26") + "&birthday=" + GlobalConts.dateFormat.format(baseinfos.get(0).getBIRTHDAY()) + "&userSource=familyDoctor";
            Log.e("返回值", "----->get" + JianKangXiaoZhanURl.REGISTER + parms);
            Request request = new Request.Builder().url(JianKangXiaoZhanURl.REGISTER + parms).build();

            //Call 将你的请求封装成任务
            Call call = client.newCall(request);
            //请求调度
            call.enqueue(new Callback() {
                //失败
                @Override
                public void onFailure(Call call, IOException e) {

                }

                //成功
                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    //返回String
                    String json = response.body().string();
                    Log.e("返回值", "----->get" + json);
                    try {
                        JSONObject js = new JSONObject(json);
                        JSONArray jsonArray = js.getJSONArray("inforList");
                        Log.e("返回值", "----->get" + jsonArray.length());
                        if ("0".equals(js.getString("respCode"))) {

                            //上传血压
                            JSONObject bean = jsonArray.getJSONObject(0);
                            String id = bean.getString("id");
                            if("xueya".equals(type)){
                                updateXueYa(id, xiaoZhanData.get(xiaozhanCount));
                            }else if("xuetang".equals(type)){
                                updateXueTang(id,xueTangData.get(xueTangCount));
                            }


                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }
            });
        }

    }

    /**
     * 上传血压数据
     */
    public void updateXueYa(String kioskUserId, SBCL_DATA data) {
        final List<SBCL_DATA> gaos = fdbmanager.findAllByWhere(SBCL_DATA.class, "CL_TYPE='高压' and GUID='" + data.getGUID() + "'");
        final List<SBCL_DATA> dis = fdbmanager.findAllByWhere(SBCL_DATA.class, "CL_TYPE='低压' and GUID='" + data.getGUID() + "'");
        final List<SBCL_DATA> mailvs = fdbmanager.findAllByWhere(SBCL_DATA.class, "CL_TYPE='脉率' and GUID='" + data.getGUID() + "'");
        String gao = "0mmHg";
        String di = "0mmHg";
        String mailv = "0次/分";
        String KEY_DATE = "";
        String KEY_TIME = "";
        if (gaos.size() > 0) {
            gao = gaos.get(0).getCL_VALUE();
            String date = gaos.get(0).getCL_TIME();
            String[] ss = date.split(" ");
            KEY_DATE = ss[0];
            KEY_TIME = ss[1];

        }
        if (dis.size() > 0) {
            di = dis.get(0).getCL_VALUE();
        }
        if (mailvs.size() > 0) {
            mailv = mailvs.get(0).getCL_VALUE();
        }
        int pingjun = 0;
        pingjun = (Integer.parseInt(gao.substring(0, gao.length() - 4)) + 2 * Integer.parseInt(di.substring(0, di.length() - 4))) / 3;


        OkHttpClient client = new OkHttpClient();
        String parms = "?SysSource=4&InteractiveDevice=familyDoctor&CollectDevice=NOVABP&DEVICE_ID=" + GlobalConts.generateIMEI(getApplicationContext()) + "&KEY_DeviceType=20&kioskUserId=" + kioskUserId + "&KEY_1=" + gao.substring(0, gao.length() - 4) + "&KEY_2=" + di.substring(0, di.length() - 4) + "&KEY_3=" + mailv.substring(0, mailv.length() - 3) + "&mean=" + pingjun + "&KEY_DATE=" + KEY_DATE + "&KEY_TIME=" + KEY_TIME;
        Log.e("血压", parms);
        Request request = new Request.Builder().url(JianKangXiaoZhanURl.UPDATEXUEYA + parms).build();

        //Call 将你的请求封装成任务
        Call call = client.newCall(request);
        //请求调度
        call.enqueue(new Callback() {
            //失败
            @Override
            public void onFailure(Call call, IOException e) {

            }

            //成功
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //返回String
                String json = response.body().string();
                Log.e("返回值", "----->get" + json);


                if ("1".equals(json)) {
                    gaos.get(0).setIS_UPDATE_JKXZ("N");
                    dis.get(0).setIS_UPDATE_JKXZ("N");
                    mailvs.get(0).setIS_UPDATE_JKXZ("N");
                    fdbmanager.updata(gaos.get(0));
                    fdbmanager.updata(dis.get(0));
                    fdbmanager.updata(mailvs.get(0));
                    xiaozhanCount++;
                    Log.e("***", "运行一个" + xiaozhanCount);
                    mHandler1.sendEmptyMessage(0);

                }
            }
        });
    }

    /**
     * 上传血糖数据
     */
    public void updateXueTang(String kioskUserId, final SBCL_DATA data){
        String KEY_DATE = "";
        String KEY_TIME = "";
        String[] ss = data.getCL_TIME().split(" ");
        KEY_DATE = ss[0];
        KEY_TIME = ss[1];
        OkHttpClient client = new OkHttpClient();
        String parms = "?SysSource=4&InteractiveDevice=familyDoctor&CollectDevice=NOVABG&DEVICE_ID=" + GlobalConts.generateIMEI(getApplicationContext()) + "&KEY_DeviceType=24&kioskUserId=" + kioskUserId + "&KEY_1=" + data.getCL_VALUE().substring(0, data.getCL_VALUE().length() - 6) +"&KEY_3=0" + "&KEY_DATE=" + KEY_DATE + "&KEY_TIME=" + KEY_TIME;
        Log.e("血糖", parms);
        Request request = new Request.Builder().url(JianKangXiaoZhanURl.UPDATEXUEYA + parms).build();

        //Call 将你的请求封装成任务
        Call call = client.newCall(request);
        //请求调度
        call.enqueue(new Callback() {
            //失败
            @Override
            public void onFailure(Call call, IOException e) {

            }

            //成功
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //返回String
                String json = response.body().string();
                Log.e("返回值", "----->get" + json);


                if ("1".equals(json)) {
                    data.setIS_UPDATE_JKXZ("N");

                    fdbmanager.updata(data);
                    xueTangCount++;
                    Log.e("***", "运行一个" + xueTangCount);
                    mHandler1.sendEmptyMessage(1);

                }
            }
        });


    }

    public void addListeners() {
        btn_back.setOnClickListener(this);

        gd_menu1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (!GlobalConts.isNetworkAvailable(DataDownLoadMainActivity.this)) {
                    showTextDialog("请先检查网络");
                    return;
                }
                if (checkToken()) {
                    showTextDialog("试用状态下无法进行数据下载!");
                    return;
                }
                cleanData();
                if (resultDialog == null) {
                    resultDialog = new ResultTextDialog(DataDownLoadMainActivity.this);
                }

                if (position == 1) {
                    //向家庭医生传递数据只有建档数据和测量历史数据
//                    getDataUp();
                     List<MeasurementDataNew> dataList = MeasurementDataNew.converData().getDataList();
                     if(dataList.size()>0){
                         updata_SBCL();
                     }else{
                         showTextDialog("无数据可上传");
                     }
                    return;
                }else if (position == 2) {//同步健康小站数据
//                    List<SBCL_DATA> list = fdbmanager.findAllByWhere(SBCL_DATA.class, "IS_UPDATE_JKXZ is not 'N' and CL_TYPE='高压'",
//                            "CL_TIME desc");
//                    xiaoZhanData=list;
//                    List<SBCL_DATA> listXueTang=fdbmanager.findAllByWhere(SBCL_DATA.class,"IS_UPDATE_JKXZ is not 'N' and CL_TYPE='血糖'",
//                            "CL_TIME desc");
//                    xueTangData=listXueTang;
//                    if (list.size() > 0) {
//                        tongBuJKXZYH(list);
//                    }else if(listXueTang.size()>0){
//                        tongBuXueTang(listXueTang);
//                    }else {
//                        showTextDialog("无数据可同步");
//                    }
                    //上传档案数据 原来对接得接口马建波在的时候 不知道是哪个平台  按照王总已经注释
//                    upLoadArchivesUpData();
                    // 上传档案到新平台
                    upLoadArchivesUpDataNew();
//                    ArchiveUpload.searchDbData();
                } else if (position == 3) {
                    //体检数据上传
//                    upLoadFollowUpData();
                    upLoadSbclDataNew();
                } else if (position == 4) {
                    //上传随访数据
                    upLoadFollowUpData();
                } else if (position == 0) {
                    isUploadPicture = false;
                    convertDataInfo = HdPersonalInfo.convertData(DataDownLoadMainActivity.this);
                    convertDataTnb =
                            Diabetes.convertData(DataDownLoadMainActivity.this);
                    Log.e("糖尿病", convertDataTnb.size() + "*********");
                    /* 肺结核第一次随访*/
                    convertDataFjhBaseInfo =
                            TuberculosisBaseInfo.convertData(DataDownLoadMainActivity.this);
                    /* 肺结核随访信息*/
                    convertDataFjhFollowUpInfo =
                            TuberculosisFollowUpInfo.convertData(DataDownLoadMainActivity.this);
                    convertDataGxy =
                            Hypertensio.convertData(DataDownLoadMainActivity.this);
                    Log.e("高血压", convertDataGxy.size() + "*********");
                    if (convertDataGxy.size() > 0) {
                        Log.e("personalid", convertDataGxy.get(0).getPersonalid() + "*********");
                    }
//                    sendFollowTable();
                    convertDataGXB =
                            CoronaryHeartDisease.convertData(DataDownLoadMainActivity.this);
                    convertDataNCZ =
                            HdDiseaseManageStroke.convertData(DataDownLoadMainActivity.this);
                    convertDataJktj =
                            HealthCheck.convertData(DataDownLoadMainActivity.this);
                    convertDataLnrzyy =
                            OldPhysique.convertData(DataDownLoadMainActivity.this);
                    convertDataLnrzlnl =
                            OldSelfHelp.convertData(DataDownLoadMainActivity.this);
                    convertDataXSRFS =
                            ChildhealthNeonate.convertData(DataDownLoadMainActivity.this);
                    convertDataOneMonth =
                            ChildWithOneYearOld.convertData(DataDownLoadMainActivity.this, "1");
                    convertDataThreeMonth =
                            ChildWithOneYearOld.convertData(DataDownLoadMainActivity.this, "2");
                    convertDataSixMonth =
                            ChildWithOneYearOld.convertData(DataDownLoadMainActivity.this, "3");
                    convertData8Month =
                            ChildWithOneYearOld.convertData(DataDownLoadMainActivity.this, "4");
                    /*获取12月龄上传参数*/
                    convertData12Month =
                            MonthsChildHomeVisit.convertData(DataDownLoadMainActivity.this, "1");
                    /*获取18月龄上传参数*/
                    convertData18Month =
                            MonthsChildHomeVisit.convertData(DataDownLoadMainActivity.this, "2");
                    /*获取24月龄上传参数*/
                    convertData24Month =
                            MonthsChildHomeVisit.convertData(DataDownLoadMainActivity.this, "3");
                    /*获取30月龄上传参数*/
                    convertData30Month =
                            MonthsChildHomeVisit.convertData(DataDownLoadMainActivity.this, "4");
                    /*获取3岁上传参数*/
                    convertData3Year =
                            YearChildHomeVisit.convertData(DataDownLoadMainActivity.this, "3");
                    /*获取4岁上传参数*/
                    convertData4Year =
                            YearChildHomeVisit.convertData(DataDownLoadMainActivity.this, "4");
                    /*获取5岁上传参数*/
                    convertData5Year =
                            YearChildHomeVisit.convertData(DataDownLoadMainActivity.this, "5");
                    /*获取6岁上传参数*/
                    convertData6Year =
                            YearChildHomeVisit.convertData(DataDownLoadMainActivity.this, "6");
                    /*第一次产前访视*/
                    convertDataTheFirstTimePrenatalVisit =
                            FirstPrenatalVisit.convertData(DataDownLoadMainActivity.this);
                    /* 第2次产前随访*/
                    convertData2TimesPrenatalVisits =
                            SecondToFifthPrenatalVisits.convertData(DataDownLoadMainActivity.this, "2");
                    /* 第3次产前随访*/
                    convertData3TimesPrenatalVisits =
                            SecondToFifthPrenatalVisits.convertData(DataDownLoadMainActivity.this, "3");
                    /* 第4次产前随访*/
                    convertData4TimesPrenatalVisits =
                            SecondToFifthPrenatalVisits.convertData(DataDownLoadMainActivity.this, "4");
                    /* 第5次产前随访*/
                    convertData5TimesPrenatalVisits =
                            SecondToFifthPrenatalVisits.convertData(DataDownLoadMainActivity.this, "5");
                    /*孕产妇产后访视*/
                    convertDataMaternalPostnatalVisits =
                            MaternalPostnatalVisits.convertData(DataDownLoadMainActivity.this);
                    /*孕产妇产后42天健康检查*/
                    convertDataMaternalFortyTwoDaysVisits =
                            MaternalFortyTwoDaysVisits.convertData(DataDownLoadMainActivity.this);

                    converJsjbInfo = JsjbBaseInfo.convertData(DataDownLoadMainActivity.this);
                    converJsjbsfb = Jsjbsfb.convertData(DataDownLoadMainActivity.this);
                    contsQyyh= QyinfoUploadBean.convertData(DataDownLoadMainActivity.this);
                    if(NovaApplication.dbManger.checkColumnExists("LvYueFuWuBean","is_Update")&&NovaApplication.dbManger.checkColumnExists("LvYueFuWuBean","creater")){
                        lvYueFuWuBeans=NovaApplication.fdbmanger.findAllByWhere(LvYueFuWuBean.class,"is_Update is not 'N'"+"and creater='"+NovaApplication.getJgrno()+"'");
                    }else{
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","is_Update");
                        NovaApplication.dbManger.addColumnByBySQL("LvYueFuWuBean","creater");
                        List<LvYueFuWuBean> list=NovaApplication.fdbmanger.findAllByWhere(LvYueFuWuBean.class,"is_Update is not 'N'");
                        if(list.size()>0){
                            for(LvYueFuWuBean lvYueFuWuBean:list){
                                lvYueFuWuBean.setIs_Update("Y");
                                lvYueFuWuBean.setCreater(NovaApplication.getJgrno());
                                NovaApplication.fdbmanger.updata(lvYueFuWuBean);
                            }
                        }
                        lvYueFuWuBeans=NovaApplication.fdbmanger.findAllByWhere(LvYueFuWuBean.class,"is_Update is not 'N'"+"and creater='"+NovaApplication.getJgrno()+"'");
                    }
                    //获取未上传肺心病随访数据
                    feiXinBingFollowups=FeiXinBing.convertData(DataDownLoadMainActivity.this);
                    //获取未上传类风湿随访数据
                    leiFengShiFollowups= LeiFengShi.convertData(DataDownLoadMainActivity.this);
                    //获取未上传慢阻肺随访数据
                    manZuFeiFollowups=ManZuFei.convertData(DataDownLoadMainActivity.this);
                    //获取未上传风湿病随访数据
                    fengShiBingFollowups=FengShiBing.convertData(DataDownLoadMainActivity.this);





                    pictures = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                            "createrId='" + SPUtil.getstr_jdrusername(DataDownLoadMainActivity.this) + "' AND isUpdate ='Y'");
                    List<JTYS_SignPictureData> pictures1 = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                            "createrId='" + SPUtil.getStr_jdrno(DataDownLoadMainActivity.this) + "' AND isUpdate ='Y'");
                    if(pictures1.size()>0){
                        pictures.addAll(pictures1);
                    }
                   for(JTYS_SignPictureData jtys_signPictureData:pictures){
                       jtys_signPictureData.setCardNum(TextUtils.isEmpty(jtys_signPictureData.getCardNum()) ? "" : jtys_signPictureData.getCardNum().toUpperCase());
                   }
                    evaluates = NovaApplication.fdbmanger.findAllByWhere(JTYSDoctorEvaluateBean.class,
                            "CREATER='" + NovaApplication.getJgrno() + "' AND SIGN ='0'");
                    for(JTYSDoctorEvaluateBean jtysDoctorEvaluateBean:evaluates){
                        jtysDoctorEvaluateBean.setCardNum(TextUtils.isEmpty(jtysDoctorEvaluateBean.getCardNum()) ? "" : jtysDoctorEvaluateBean.getCardNum().toUpperCase());
                    }

                    handler.sendEmptyMessage(1);

                    return;
                }
            }

        });
    }

    int s = 0;
    int f = 0;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 11:
                    showTextDialog("正在上传," + "  成功：" + s + "  失败：" + f);
                    String count = (String) msg.getData().get("count");
                    System.out.println("拉取数据："+count);
                    String[] counts = count.split("/");
                    s = s + Integer.parseInt(counts[0]);
                    f = f + Integer.parseInt(counts[1]);
                    String name = counts[2];
                    uploadSuccessData(name);
                    break;
                case 1:
                    if (convertDataInfo.size() == 0 &&
                            convertDataTnb.size() == 0 &&
                            convertDataFjhBaseInfo.size() == 0 &&
                            convertDataFjhFollowUpInfo.size() == 0 &&
                            convertDataGXB.size() == 0 &&
                            convertDataNCZ.size() == 0 &&
                            convertDataGxy.size() == 0 &&
                            convertDataJktj.size() == 0 &&
                            convertDataLnrzyy.size() == 0 &&
                            convertDataLnrzlnl.size() == 0 &&
                            convertDataXSRFS.size() == 0 &&
                            convertDataOneMonth.size() == 0 &&
                            convertDataThreeMonth.size() == 0 &&
                            convertDataSixMonth.size() == 0 &&
                            convertData8Month.size() == 0 &&
                            convertData12Month.size() == 0 &&
                            convertData18Month.size() == 0 &&
                            convertData24Month.size() == 0 &&
                            convertData30Month.size() == 0 &&
                            convertData3Year.size() == 0 &&
                            convertData4Year.size() == 0 &&
                            convertData5Year.size() == 0 &&
                            convertData6Year.size() == 0 &&
                            convertDataTheFirstTimePrenatalVisit.size() == 0 &&
                            convertData2TimesPrenatalVisits.size() == 0 &&
                            convertData3TimesPrenatalVisits.size() == 0 &&
                            convertData4TimesPrenatalVisits.size() == 0 &&
                            convertData5TimesPrenatalVisits.size() == 0 &&
                            convertDataMaternalPostnatalVisits.size() == 0 &&
                            convertDataMaternalFortyTwoDaysVisits.size() == 0 &&
                            converJsjbInfo.size() == 0 &&
                            converJsjbsfb.size() == 0 &&
                            pictures.size() == 0 &&
                            contsQyyh.size() == 0 &&
                            evaluates.size() == 0&&
                            lvYueFuWuBeans.size()==0&&
                            feiXinBingFollowups.size()==0&&
                            leiFengShiFollowups.size()==0&&
                            manZuFeiFollowups.size()==0&&
                            fengShiBingFollowups.size()==0) {




                        showTextDialog("无数据可上传");
                        return;
                    }

                    upNextData(ModuleName.UPLOAD_SELFINFO);
                    break;
                case 2:
                    if (contsQyyh.size() == 0 && evaluates.size() == 0) {
                        showTextDialog("无数据可上传");
                        return;
                    }
                    if (contsQyyh != null && contsQyyh.size() > 0) {
                        upDataQYYH();
                    } else if (evaluates != null && evaluates.size() > 0) {
                        upDataFWMYD();
                    }
                    break;
            }
        }
    };

    /**
     * 数据上传成功之后执行操作
     *
     * @param name
     */
    private void uploadSuccessData(String name) {
        if (ModuleName.UPLOAD_SELFINFO.equals(name)) {
            if (convertDataInfo != null && convertDataInfo.size() > 0) {
                upDataJBXX();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_TNB);
            }
        } else if (ModuleName.UPLOAD_TNB.equals(name)) {
            if (convertDataTnb != null && convertDataTnb.size() > 0) {
                upDataTNB();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_TNB_DYCSF);
            }
        } else if (ModuleName.UPLOAD_TNB_DYCSF.equals(name)) {
            /*肺结核第一次随访*/
            if (convertDataFjhBaseInfo != null && convertDataFjhBaseInfo.size() > 0) {
                upDataFjhDycsf();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_TNB_SFXX);
            }
        } else if (ModuleName.UPLOAD_TNB_SFXX.equals(name)) {
            /*肺结核随访信息*/
            if (convertDataFjhFollowUpInfo != null && convertDataFjhFollowUpInfo.size() > 0) {
                upDataFjhSfxx();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_NCZ);
            }
        } else if (ModuleName.UPLOAD_NCZ.equals(name)) {
            if (convertDataNCZ != null && convertDataNCZ.size() > 0) {
                updateNCZ();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_GXB);
            }
        } else if (ModuleName.UPLOAD_GXB.equals(name)) {
            if (convertDataGXB != null && convertDataGXB.size() > 0) {
                updateGXB();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_GXY);
            }
        } else if (ModuleName.UPLOAD_GXY.equals(name)) {
            if (convertDataGxy != null && convertDataGxy.size() > 0) {
                updateGXY();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_HEALTH_EXAMINATION);
            }
        } else if (ModuleName.UPLOAD_HEALTH_EXAMINATION.equals(name)) {
            if (convertDataJktj != null && convertDataJktj.size() > 0) {
                updaTaJKTJ();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_ELDERLY_MEDICINE);
            }
        } else if (ModuleName.UPLOAD_ELDERLY_MEDICINE.equals(name)) {
            if (convertDataLnrzyy != null && convertDataLnrzyy.size() > 0) {
                upDataLNRZYY();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_ELDERLY_SELFCARE_ABILITY);
            }
        } else if (ModuleName.UPLOAD_ELDERLY_SELFCARE_ABILITY.equals(name)) {
            if (convertDataLnrzlnl != null && convertDataLnrzlnl.size() > 0) {
                upDataLNRZLNL();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_NEWBORN_VISITS);
            }
        } else if (ModuleName.UPLOAD_CHILD_NEWBORN_VISITS.equals(name)) {
            if (convertDataXSRFS != null && convertDataXSRFS.size() > 0) {
                upDataXSEFS();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_1MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_1MONTH_AGE_VISIT.equals(name)) {
            if (convertDataOneMonth != null && convertDataOneMonth.size() > 0) {
                upDataMYLET();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_3MONTH_AGE_VISIT);
            }

        } else if (ModuleName.UPLOAD_CHILD_3MONTH_AGE_VISIT.equals(name)) {
            if (convertDataThreeMonth != null && convertDataThreeMonth.size() > 0) {
                upDataSYLET();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_6MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_6MONTH_AGE_VISIT.equals(name)) {
            if (convertDataSixMonth != null && convertDataSixMonth.size() > 0) {
                upDataLYLET();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_8MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_8MONTH_AGE_VISIT.equals(name)) {
            if (convertData8Month != null && convertData8Month.size() > 0) {
                upDataBYLET();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_12MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_12MONTH_AGE_VISIT.equals(name)) {
            /*12月龄儿童家庭访视*/
            if (convertData12Month != null && convertData12Month.size() > 0) {
                upDataSeLet();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_18MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_18MONTH_AGE_VISIT.equals(name)) {
            /*18月龄儿童家庭访视*/
            if (convertData18Month != null && convertData18Month.size() > 0) {
                upDataSbLet();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_24MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_24MONTH_AGE_VISIT.equals(name)) {
            /*24月龄儿童家庭访视*/
            if (convertData24Month != null && convertData24Month.size() > 0) {
                upDataEsLet();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_30MONTH_AGE_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_30MONTH_AGE_VISIT.equals(name)) {
            /*30月龄儿童家庭访视*/
            if (convertData30Month != null && convertData30Month.size() > 0) {
                upDataSsLet();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_3YEAR_HOME_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_3YEAR_HOME_VISIT.equals(name)) {
            /*3岁儿童家庭访视*/
            if (convertData3Year != null && convertData3Year.size() > 0) {
                upData3YearVisitInfo();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_4YEAR_HOME_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_4YEAR_HOME_VISIT.equals(name)) {
            /*4岁儿童家庭访视*/
            if (convertData4Year != null && convertData4Year.size() > 0) {
                upData4YearVisitInfo();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_5YEAR_HOME_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_5YEAR_HOME_VISIT.equals(name)) {
            /*5岁儿童家庭访视*/
            if (convertData5Year != null && convertData5Year.size() > 0) {
                upData5YearVisitInfo();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_CHILD_6YEAR_HOME_VISIT);
            }
        } else if (ModuleName.UPLOAD_CHILD_6YEAR_HOME_VISIT.equals(name)) {
            /*6岁儿童家庭访视*/
            if (convertData6Year != null && convertData6Year.size() > 0) {
                upData6YearVisitInfo();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_1TIMES_PRENATAL_VISIT);
            }
        } else if (ModuleName.UPLOAD_PREGNANT_1TIMES_PRENATAL_VISIT.equals(name)) {
            /*第一次产前访视*/
            if (convertDataTheFirstTimePrenatalVisit != null && convertDataTheFirstTimePrenatalVisit.size() > 0) {
                upDataFirstPrenatalVisit();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_2TIMES_PRENATAL_VISIT);

            }
        } else if (ModuleName.UPLOAD_PREGNANT_2TIMES_PRENATAL_VISIT.equals(name)) {
            /* 第二次产前访视*/
            if (convertData2TimesPrenatalVisits != null && convertData2TimesPrenatalVisits.size() > 0) {
                upDataSecondPrenatalVisits();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_3TIMES_PRENATAL_VISIT);

            }
        } else if (ModuleName.UPLOAD_PREGNANT_3TIMES_PRENATAL_VISIT.equals(name)) {
            /* 第三次产前访视*/
            if (convertData3TimesPrenatalVisits != null && convertData3TimesPrenatalVisits.size() > 0) {
                upDataThirdPrenatalVisits();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_4TIMES_PRENATAL_VISIT);

            }
        } else if (ModuleName.UPLOAD_PREGNANT_4TIMES_PRENATAL_VISIT.equals(name)) {
            /* 第四次产前访视*/
            if (convertData4TimesPrenatalVisits != null && convertData4TimesPrenatalVisits.size() > 0) {
                upDataFourTimesPrenatalVisits();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_5TIMES_PRENATAL_VISIT);

            }
        } else if (ModuleName.UPLOAD_PREGNANT_5TIMES_PRENATAL_VISIT.equals(name)) {
            /* 第五次产前访视*/
            if (convertData5TimesPrenatalVisits != null && convertData5TimesPrenatalVisits.size() > 0) {
                upDataFiveTimesPrenatalVisits();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_MATERNAL_POSTNATAL_VISITS);

            }
        } else if (ModuleName.UPLOAD_PREGNANT_MATERNAL_POSTNATAL_VISITS.equals(name)) {
            /* 孕产妇产后访视*/
            if (convertDataMaternalPostnatalVisits != null && convertDataMaternalPostnatalVisits.size() > 0) {
                upDataPostnatalVisitsPrenatalVisits();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PREGNANT_MATERNAL_42DAYS_VISITS);

            }
        } else if (ModuleName.UPLOAD_PREGNANT_MATERNAL_42DAYS_VISITS.equals(name)) {
            /* 孕产妇产后42天健康检查*/
            if (convertDataMaternalFortyTwoDaysVisits != null && convertDataMaternalFortyTwoDaysVisits.size() > 0) {
                upData42DaysPrenatalVisits();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_JSJB_BASEINFO);

            }
        } else if (ModuleName.UPLOAD_JSJB_BASEINFO.equals(name)) {
            if (converJsjbInfo != null && converJsjbInfo.size() > 0) {
                updateJSJBInfo();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_JSJB_FOLLOWUP);

            }
        } else if (ModuleName.UPLOAD_JSJB_FOLLOWUP.equals(name)) {
            if (converJsjbsfb != null && converJsjbsfb.size() > 0) {
                updateJSJBSF();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_QYYH);

            }
        } else if (ModuleName.UPLOAD_QYYH.equals(name)) {
            if (contsQyyh != null && contsQyyh.size() > 0) {
                upDataQYYH();
            } else {
                pictures = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                        "createrId='" + SPUtil.getstr_jdrusername(DataDownLoadMainActivity.this) + "' AND isUpdate ='Y'");
                List<JTYS_SignPictureData> pictures1 = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                        "createrId='" + SPUtil.getStr_jdrno(DataDownLoadMainActivity.this) + "' AND isUpdate ='Y'");
                if(pictures1.size()>0){
                    pictures.addAll(pictures1);
                }
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_FWMYD);

            }
        } else if (ModuleName.UPLOAD_FWMYD.equals(name)) {
            if (evaluates != null && evaluates.size() > 0) {
                upDataFWMYD();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_PHOTO);
            }
        } else if (ModuleName.UPLOAD_PHOTO.equals(name)) {
            List<JTYS_SignPictureData> pictures1 = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                    "createrId='" + SPUtil.getstr_jdrusername(DataDownLoadMainActivity.this) + "' AND isUpdate ='Y'");
            List<JTYS_SignPictureData> pictures2 = NovaApplication.fdbmanger.findAllByWhere(JTYS_SignPictureData.class,
                    "createrId='" + SPUtil.getStr_jdrno(DataDownLoadMainActivity.this) + "' AND isUpdate ='Y'");
            if(pictures2.size()>0){
                pictures1.addAll(pictures2);
            }
            if (pictures != null && pictures.size() > 0 && !isUploadPicture) {
                upDataPhoto();
                count++;
                if (count == pictures1.size()){
                    successUd(name);
                    count = 0;
                    return;
                }
            } else {
                successUd(name);
                upNextData(ModuleName.UPLOAD_LVYUEJL);
            }
        }else if(ModuleName.UPLOAD_LVYUEJL.equals(name)){
            if (lvYueFuWuBeans != null && lvYueFuWuBeans.size() > 0) {
                upDataLvYueJL();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPLOAD_FEIXINBING);

            }
        }
        else if(ModuleName.UPLOAD_FEIXINBING.equals(name)){
            if (feiXinBingFollowups != null && feiXinBingFollowups.size() > 0) {
                updateFeiXinBing();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPDATE_LEIFENGSHI);

            }
        }else if(ModuleName.UPDATE_LEIFENGSHI.equals(name)){
            if (leiFengShiFollowups != null && leiFengShiFollowups.size() > 0) {
                updateLeiFengshi();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPDATE_MANZUFEI);

            }
        }else if(ModuleName.UPDATE_MANZUFEI.equals(name)){
            if (manZuFeiFollowups != null && manZuFeiFollowups.size() > 0) {
                updateManZuFei();
            } else {
                successUd(name);
//                            uploadOtherData();
                upNextData(ModuleName.UPDATE_FENGSHIBING);

            }
        }else if(ModuleName.UPDATE_FENGSHIBING.equals(name)){
            if (fengShiBingFollowups != null && fengShiBingFollowups.size() > 0) {
                updateFengShiBing();
            } else {
                successUd(name);
//                            uploadOtherData();
//                upNextData(ModuleName.UPDATE_FENGSHIBING);

            }
        }
    }

    private boolean isUploadPicture = false;

    /**
     * 上传除去个人基本信息之外的所有信息
     */
    private void uploadOtherData() {
        if (convertDataTnb != null && convertDataTnb.size() > 0) {
            upDataTNB();
        } else if (convertDataFjhBaseInfo != null && convertDataFjhBaseInfo.size() > 0) {
            /*肺结核第一次随访*/
            upDataFjhDycsf();
        } else if (convertDataFjhFollowUpInfo != null && convertDataFjhFollowUpInfo.size() > 0) {
            /*肺结核随访信息*/
            upDataFjhSfxx();
        } else if (convertDataNCZ != null && convertDataNCZ.size() > 0) {
            updateNCZ();
        } else if (convertDataGXB != null && convertDataGXB.size() > 0) {
            updateGXB();
        } else if (convertDataGxy != null && convertDataGxy.size() > 0) {
            updateGXY();
        } else if (convertDataJktj != null && convertDataJktj.size() > 0) {
            updaTaJKTJ();
        } else if (convertDataLnrzyy != null && convertDataLnrzyy.size() > 0) {
            upDataLNRZYY();
        } else if (convertDataLnrzlnl != null && convertDataLnrzlnl.size() > 0) {
            upDataLNRZLNL();
        } else if (convertDataXSRFS != null && convertDataXSRFS.size() > 0) {
            upDataXSEFS();
        } else if (convertDataOneMonth != null && convertDataOneMonth.size() > 0) {
            upDataMYLET();
        } else if (convertDataThreeMonth != null && convertDataThreeMonth.size() > 0) {
            upDataSYLET();
        } else if (convertDataSixMonth != null && convertDataSixMonth.size() > 0) {
            upDataLYLET();
        } else if (convertData8Month != null && convertData8Month.size() > 0) {
            upDataBYLET();
        } else if (convertData12Month != null && convertData12Month.size() > 0) {
            upDataSeLet();
        } else if (convertData18Month != null && convertData18Month.size() > 0) {
            upDataSbLet();
        } else if (convertData24Month != null && convertData24Month.size() > 0) {
            upDataEsLet();
        } else if (convertData30Month != null && convertData30Month.size() > 0) {
            upDataSsLet();
        } else if (convertData3Year != null && convertData3Year.size() > 0) {
            upData3YearVisitInfo();
        } else if (convertData4Year != null && convertData4Year.size() > 0) {
            upData4YearVisitInfo();
        } else if (convertData5Year != null && convertData5Year.size() > 0) {
            upData5YearVisitInfo();
        } else if (convertData6Year != null && convertData6Year.size() > 0) {
            upData6YearVisitInfo();
        } else if (convertDataTheFirstTimePrenatalVisit != null && convertDataTheFirstTimePrenatalVisit.size() > 0) {
            /* 第一次产前访视*/
            upDataFirstPrenatalVisit();
        } else if (convertData2TimesPrenatalVisits != null && convertData2TimesPrenatalVisits.size() > 0) {
            /* 第二次产前访视*/
            upDataSecondPrenatalVisits();
        } else if (convertData3TimesPrenatalVisits != null && convertData3TimesPrenatalVisits.size() > 0) {
            /* 第三次产前访视*/
            upDataThirdPrenatalVisits();
        } else if (convertData4TimesPrenatalVisits != null && convertData4TimesPrenatalVisits.size() > 0) {
            /* 第四次产前访视*/
            upDataFourTimesPrenatalVisits();
        } else if (convertData5TimesPrenatalVisits != null && convertData5TimesPrenatalVisits.size() > 0) {
            /* 第五次产前访视*/
            upDataFiveTimesPrenatalVisits();
        } else if (convertDataMaternalPostnatalVisits != null && convertDataMaternalPostnatalVisits.size() > 0) {
            /* 孕产妇产后访视*/
            upDataPostnatalVisitsPrenatalVisits();
        } else if (convertDataMaternalFortyTwoDaysVisits != null && convertDataMaternalFortyTwoDaysVisits.size() > 0) {
            /* 孕产妇产后42天健康检查*/
            upData42DaysPrenatalVisits();
        } else if (converJsjbInfo != null && converJsjbInfo.size() > 0) {
            updateJSJBInfo();
        } else if (converJsjbsfb != null && converJsjbsfb.size() > 0) {
            updateJSJBSF();
        } else if (contsQyyh != null && contsQyyh.size() > 0) {
            upDataQYYH();
        } else if (evaluates != null && evaluates.size() > 0) {
            upDataFWMYD();
        } else if (pictures != null && pictures.size() > 0) {
            upDataPhoto();
        }
    }

    private void upDataPhoto() {
        List list = new ArrayList<>();
        List<JTYS_SignPictureData> newList = null;
        if (pictures.size() > 0) {
            newList = pictures.subList(0, 1);
            pictures = pictures.subList(1, pictures.size());
        } else {
            newList = pictures;
            pictures = null;
        }

        UploadDataBean udb9 = new UploadDataBean("照片", JX_UploadData.TYPE_PICTURE, "json", "uploadFile", "", newList);
        list.add(udb9);
        showProgressDialog(udb9.getDataName() + "数据正在上传中，图片数据比较大，请耐心等待...");
        final UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();
                uld.uploadDatas();
                Looper.loop();
            }
        }).start();
    }

    public void successUd(String name) {
        cancelProgressDialog();
        showTextDialog(name + "上传完成," + "  成功：" + s + "  失败：" + f);
        Log.e("**********", name + "上传完成" + "成功：" + s + "失败：" + f);
        s = 0;
        f = 0;
        if (ModuleName.UPLOAD_PHOTO.equals(name)){
            isUploadPicture = true;
        }
    }


    private void wait(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    }

    /**
     * 基本信息
     */
    public void upDataJBXX() {
        List list = new ArrayList<>();
        // 个人基本信息
        List<HdPersonalInfo> newList = null;

        if (convertDataInfo.size() > subSize) {
            newList = convertDataInfo.subList(0, subSize);
            convertDataInfo = convertDataInfo.subList(subSize, convertDataInfo.size());
            Log.e("*************", newList.size() + "***" + convertDataInfo.size() + "*******************");
        } else {
            newList = convertDataInfo;
            convertDataInfo = null;
        }
        for (int i = 0, size = newList.size(); i < size; i++) {
            if (TextUtils.isEmpty(newList.get(i).getModified())) {
                newList.get(i).setModified(newList.get(i).getCreater());
            }
        }
        UploadDataBean udb1 = new UploadDataBean(ModuleName.UPLOAD_SELFINFO, JX_UploadData.TYPE_PERSONALINFO, "jsonStr",
                "addHdPersonalInfo", "grjbxx", newList);
        list.add(udb1);
        showProgressDialog(udb1.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 糖尿病
     */
    public void upDataTNB() {
        List list = new ArrayList<>();
        // 糖尿病
        List<Diabetes> newList = new ArrayList<>();

        for (Diabetes diabetes : newList){
            System.out.println("上传数据："+diabetes.getCardid());
        }
        if (convertDataTnb.size() > 10) {
            newList = convertDataTnb.subList(0, subSize);
            convertDataTnb = convertDataTnb.subList(subSize, convertDataTnb.size());
            Log.e("*************", newList.size() + "***" + convertDataTnb.size() + "*******************");
        } else {
            newList = convertDataTnb;
            convertDataTnb = null;
        }

        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPLOAD_TNB,
                JX_UploadData.TYPE_DIABETES, "TnbJson",
                "addTnb", "tnb", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 肺结核第一次随访
     */
    public void upDataFjhDycsf() {
        List list = new ArrayList<>();
        //肺结核第一次随访
        List<TuberculosisBaseInfo> newList = null;

        if (convertDataFjhBaseInfo.size() > 10) {
            newList = convertDataFjhBaseInfo.subList(0, subSize);
            convertDataFjhBaseInfo = convertDataFjhBaseInfo.subList(subSize, convertDataFjhBaseInfo.size());
            Log.e("*************", newList.size() + "***" + convertDataFjhBaseInfo.size() + "*******************");
        } else {
            newList = convertDataFjhBaseInfo;
            convertDataFjhBaseInfo = null;
        }

        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPLOAD_TNB_DYCSF,
                JX_UploadData.TYPE_TUBERCULOSIS_BASE_INFO, "TubJson",
                "addTubtoFirst", "tnb", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 肺结核随访信息
     */
    public void upDataFjhSfxx() {
        List list = new ArrayList<>();
        // 肺结核随访信息
        List<TuberculosisFollowUpInfo> newList = null;

        if (convertDataFjhFollowUpInfo.size() > 10) {
            newList = convertDataFjhFollowUpInfo.subList(0, subSize);
            convertDataFjhFollowUpInfo = convertDataFjhFollowUpInfo.subList(subSize, convertDataFjhFollowUpInfo.size());
            Log.e("*************", newList.size() + "***" + convertDataFjhFollowUpInfo.size() + "*******************");
        } else {
            newList = convertDataFjhFollowUpInfo;
            convertDataFjhFollowUpInfo = null;
        }

        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPLOAD_TNB_SFXX,
                JX_UploadData.TYPE_TUBERCULOSIS_FOLLOW_INFO, "TbFollowJson",
                "addTbFollow", "tnb", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 脑卒中
     */
    private void updateNCZ() {
        List list = new ArrayList<>();
        // 脑卒中
        List<HdDiseaseManageStroke> newList = null;

        if (convertDataNCZ.size() > subSize) {
            newList = convertDataNCZ.subList(0, subSize);
            convertDataNCZ = convertDataNCZ.subList(subSize, convertDataNCZ.size());
            Log.e("*************", newList.size() + "***" + convertDataNCZ.size() + "*******************");
        } else {
            newList = convertDataNCZ;
            convertDataNCZ = null;
        }
        UploadDataBean udb3 = new UploadDataBean(ModuleName.UPLOAD_NCZ,
                JX_UploadData.TYPE_CEREBRALSTROKE, "StrokeJson",
                "addStroke", "ncz", newList);
        list.add(udb3);
        showProgressDialog(udb3.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 冠心病
     */
    public void updateGXB() {
        List list = new ArrayList<>();
        // 冠心病
        List<CoronaryHeartDisease> newList = null;

        if (convertDataGXB.size() > subSize) {
            newList = convertDataGXB.subList(0, subSize);
            convertDataGXB = convertDataGXB.subList(subSize, convertDataGXB.size());
            Log.e("*************", newList.size() + "***" + convertDataGXB.size() + "*******************");
        } else {
            newList = convertDataGXB;
            convertDataGXB = null;
        }

        UploadDataBean udb3 = new UploadDataBean(ModuleName.UPLOAD_GXB,
                JX_UploadData.TYPE_CORONARYHEART, "coronaryJson",
                "addCoronary", "gxb", newList);
        list.add(udb3);
        showProgressDialog(udb3.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 高血压
     */
    public void updateGXY() {
        List list = new ArrayList<>();
        // 高血压
        List<Hypertensio> newList = null;

        if (convertDataGxy.size() > subSize) {
            newList = convertDataGxy.subList(0, subSize);
            convertDataGxy = convertDataGxy.subList(subSize, convertDataGxy.size());
            Log.e("*************", newList.size() + "***" + convertDataGxy.size() + "*******************");
        } else {
            newList = convertDataGxy;
            convertDataGxy = null;
        }

        UploadDataBean udb3 = new UploadDataBean(ModuleName.UPLOAD_GXY,
                JX_UploadData.TYPE_HYPERTENSION, "HyperJson",
                "addHypertension", "gxy", newList);
        list.add(udb3);
        showProgressDialog(udb3.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 健康体检
     */
    public void updaTaJKTJ() {
        List list = new ArrayList<>();
        // 健康体检
        List<HealthCheck> newList = null;

        if (convertDataJktj.size() > 10) {
            newList = convertDataJktj.subList(0, subSize);
            convertDataJktj = convertDataJktj.subList(subSize, convertDataJktj.size());
            Log.e("*************", newList.size() + "***" + convertDataJktj.size() + "*******************");
        } else {
            newList = convertDataJktj;
            convertDataJktj = null;
        }

        UploadDataBean udb4 = new UploadDataBean(ModuleName.UPLOAD_HEALTH_EXAMINATION,
                JX_UploadData.TYPE_HEALTHCHECK, "JktjAllJson",
                "addJktjAll", "jktj", newList);
        list.add(udb4);
        showProgressDialog(udb4.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 老年人中医药
     */
    public void upDataLNRZYY() {
        List list = new ArrayList<>();
        // 老年人中医药
        List<OldPhysique> newList = null;

        if (convertDataLnrzyy.size() > subSize) {
            newList = convertDataLnrzyy.subList(0, subSize);
            convertDataLnrzyy = convertDataLnrzyy.subList(subSize, convertDataLnrzyy.size());
            Log.e("*************", newList.size() + "***" + convertDataLnrzyy.size() + "*******************");
        } else {
            newList = convertDataLnrzyy;
            convertDataLnrzyy = null;
        }

        UploadDataBean udb5 = new UploadDataBean(ModuleName.UPLOAD_ELDERLY_MEDICINE,
                JX_UploadData.TYPE_OLD_PHYSIQUE,
                "OldPhysiqueJson", "addOldPhysique", "oldPhysic",
                newList);
        list.add(udb5);
        showProgressDialog(udb5.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 老年人自理能力
     */
    public void upDataLNRZLNL() {
        List list = new ArrayList<>();
        // 老年人自理能力
        List<OldSelfHelp> newList = null;

        if (convertDataLnrzlnl.size() > subSize) {
            newList = convertDataLnrzlnl.subList(0, subSize);
            convertDataLnrzlnl = convertDataLnrzlnl.subList(subSize, convertDataLnrzlnl.size());
            Log.e("*************", newList.size() + "***" + convertDataLnrzlnl.size() + "*******************");
        } else {
            newList = convertDataLnrzlnl;
            convertDataLnrzlnl = null;
        }

        UploadDataBean udb6 = new UploadDataBean(ModuleName.UPLOAD_ELDERLY_SELFCARE_ABILITY,
                JX_UploadData.TYPE_OLD_SELF_HELP,
                "OlsSelfHelpJson", "addOldSelfHelp", "oldself",
                newList);
        list.add(udb6);
        showProgressDialog(udb6.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 第一次产前访视
     */
    public void upDataFirstPrenatalVisit() {
        List list = new ArrayList<>();
        // 第一次产前访视
        List<FirstPrenatalVisit> newList = null;

        if (convertDataTheFirstTimePrenatalVisit.size() > subSize) {
            newList = convertDataTheFirstTimePrenatalVisit.subList(0, subSize);
            convertDataTheFirstTimePrenatalVisit = convertDataTheFirstTimePrenatalVisit.subList(subSize, convertDataTheFirstTimePrenatalVisit.size());
            Log.e("*************", newList.size() + "***" + convertDataTheFirstTimePrenatalVisit.size() + "*******************");
        } else {
            newList = convertDataTheFirstTimePrenatalVisit;
            convertDataTheFirstTimePrenatalVisit = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_1TIMES_PRENATAL_VISIT,
                JX_UploadData.TYPE_1TIMES,
                "jsonkey", "addFirstvisit", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 第2次产前随访
     */
    public void upDataSecondPrenatalVisits() {
        List list = new ArrayList<>();
        //第2次产前随访
        List<SecondToFifthPrenatalVisits> newList = null;

        if (convertData2TimesPrenatalVisits.size() > subSize) {
            newList = convertData2TimesPrenatalVisits.subList(0, subSize);
            convertData2TimesPrenatalVisits = convertData2TimesPrenatalVisits.subList(subSize, convertData2TimesPrenatalVisits.size());
            Log.e("*************", newList.size() + "***" + convertData2TimesPrenatalVisits.size() + "*******************");
        } else {
            newList = convertData2TimesPrenatalVisits;
            convertData2TimesPrenatalVisits = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_2TIMES_PRENATAL_VISIT,
                JX_UploadData.TYPE_2TIMES,
                "jsonkey", "addTwoToFiveVisit", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 第3次产前随访
     */
    public void upDataThirdPrenatalVisits() {
        List list = new ArrayList<>();
        //第2次产前随访
        List<SecondToFifthPrenatalVisits> newList = null;

        if (convertData3TimesPrenatalVisits.size() > subSize) {
            newList = convertData3TimesPrenatalVisits.subList(0, subSize);
            convertData3TimesPrenatalVisits = convertData3TimesPrenatalVisits.subList(subSize, convertData3TimesPrenatalVisits.size());
            Log.e("*************", newList.size() + "***" + convertData3TimesPrenatalVisits.size() + "*******************");
        } else {
            newList = convertData3TimesPrenatalVisits;
            convertData3TimesPrenatalVisits = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_3TIMES_PRENATAL_VISIT,
                JX_UploadData.TYPE_3TIMES,
                "jsonkey", "addTwoToFiveVisit", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 第4次产前随访
     */
    public void upDataFourTimesPrenatalVisits() {
        List list = new ArrayList<>();
        //第2次产前随访
        List<SecondToFifthPrenatalVisits> newList = null;

        if (convertData4TimesPrenatalVisits.size() > subSize) {
            newList = convertData4TimesPrenatalVisits.subList(0, subSize);
            convertData4TimesPrenatalVisits = convertData4TimesPrenatalVisits.subList(subSize, convertData4TimesPrenatalVisits.size());
            Log.e("*************", newList.size() + "***" + convertData4TimesPrenatalVisits.size() + "*******************");
        } else {
            newList = convertData4TimesPrenatalVisits;
            convertData4TimesPrenatalVisits = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_4TIMES_PRENATAL_VISIT,
                JX_UploadData.TYPE_4TIMES,
                "jsonkey", "addTwoToFiveVisit", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 第5次产前随访
     */
    public void upDataFiveTimesPrenatalVisits() {
        List list = new ArrayList<>();
        //第5次产前随访
        List<SecondToFifthPrenatalVisits> newList = null;

        if (convertData5TimesPrenatalVisits.size() > subSize) {
            newList = convertData5TimesPrenatalVisits.subList(0, subSize);
            convertData5TimesPrenatalVisits = convertData5TimesPrenatalVisits.subList(subSize, convertData5TimesPrenatalVisits.size());
            Log.e("*************", newList.size() + "***" + convertData5TimesPrenatalVisits.size() + "*******************");
        } else {
            newList = convertData5TimesPrenatalVisits;
            convertData5TimesPrenatalVisits = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_5TIMES_PRENATAL_VISIT,
                JX_UploadData.TYPE_5TIMES,
                "jsonkey", "addTwoToFiveVisit", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 孕产妇产后访视
     */
    public void upDataPostnatalVisitsPrenatalVisits() {
        List list = new ArrayList<>();
        //孕产妇产后访视
        List<MaternalPostnatalVisits> newList = null;

        if (convertDataMaternalPostnatalVisits.size() > subSize) {
            newList = convertDataMaternalPostnatalVisits.subList(0, subSize);
            convertDataMaternalPostnatalVisits = convertDataMaternalPostnatalVisits.subList(subSize, convertDataMaternalPostnatalVisits.size());
            Log.e("*************", newList.size() + "***" + convertDataMaternalPostnatalVisits.size() + "*******************");
        } else {
            newList = convertDataMaternalPostnatalVisits;
            convertDataMaternalPostnatalVisits = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_MATERNAL_POSTNATAL_VISITS,
                JX_UploadData.TYPE_POSTNATAL_VISITS,
                "jsonkey", "addPostpartum", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 孕产妇产后42天健康检查
     */
    public void upData42DaysPrenatalVisits() {
        List list = new ArrayList<>();
        //孕产妇产后42天健康检查
        List<MaternalFortyTwoDaysVisits> newList = null;

        if (convertDataMaternalFortyTwoDaysVisits.size() > subSize) {
            newList = convertDataMaternalFortyTwoDaysVisits.subList(0, subSize);
            convertDataMaternalFortyTwoDaysVisits = convertDataMaternalFortyTwoDaysVisits.subList(subSize, convertDataMaternalFortyTwoDaysVisits.size());
            Log.e("*************", newList.size() + "***" + convertDataMaternalFortyTwoDaysVisits.size() + "*******************");
        } else {
            newList = convertDataMaternalFortyTwoDaysVisits;
            convertDataMaternalFortyTwoDaysVisits = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_PREGNANT_MATERNAL_42DAYS_VISITS,
                JX_UploadData.TYPE_42DAYS,
                "jsonkey", "add42Days", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 新生儿访视
     */
    public void upDataXSEFS() {
        List list = new ArrayList<>();
        // 新生儿访视
        List<ChildhealthNeonate> newList = null;

        if (convertDataXSRFS.size() > subSize) {
            newList = convertDataXSRFS.subList(0, subSize);
            convertDataXSRFS = convertDataXSRFS.subList(subSize, convertDataXSRFS.size());
            Log.e("*************", newList.size() + "***" + convertDataXSRFS.size() + "*******************");
        } else {
            newList = convertDataXSRFS;
            convertDataXSRFS = null;
        }

        UploadDataBean udb10 = new UploadDataBean(ModuleName.UPLOAD_CHILD_NEWBORN_VISITS,
                JX_UploadData.TYPE_XSRFS,
                "jsonkey", "addChildhealthNeonate", "",
                newList);
        list.add(udb10);
        showProgressDialog(udb10.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 满月龄儿童访视
     */
    public void upDataMYLET() {
        List list = new ArrayList<>();
        // 满月龄儿童访视
        List<ChildWithOneYearOld> newList = null;

        if (convertDataOneMonth.size() > subSize) {
            newList = convertDataOneMonth.subList(0, subSize);
            convertDataOneMonth = convertDataOneMonth.subList(subSize, convertDataOneMonth.size());
            Log.e("*************", newList.size() + "***" + convertDataOneMonth.size() + "*******************");
        } else {
            newList = convertDataOneMonth;
            convertDataOneMonth = null;
        }

        UploadDataBean udb11 = new UploadDataBean(ModuleName.UPLOAD_CHILD_1MONTH_AGE_VISIT,
                JX_UploadData.TYPE_XSRFS,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb11);
        showProgressDialog(udb11.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 三月龄儿童访视
     */
    public void upDataSYLET() {
        List list = new ArrayList<>();
        // 三月龄儿童访视
        List<ChildWithOneYearOld> newList = null;

        if (convertDataThreeMonth.size() > subSize) {
            newList = convertDataThreeMonth.subList(0, subSize);
            convertDataThreeMonth = convertDataThreeMonth.subList(subSize, convertDataThreeMonth.size());
            Log.e("*************", newList.size() + "***" + convertDataThreeMonth.size() + "*******************");
        } else {
            newList = convertDataThreeMonth;
            convertDataThreeMonth = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_3MONTH_AGE_VISIT,
                JX_UploadData.TYPE_THREEMONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 六月龄儿童访视
     */
    public void upDataLYLET() {
        List list = new ArrayList<>();
        // 六月龄儿童访视
        List<ChildWithOneYearOld> newList = null;

        if (convertDataSixMonth.size() > subSize) {
            newList = convertDataSixMonth.subList(0, subSize);
            convertDataSixMonth = convertDataSixMonth.subList(subSize, convertDataSixMonth.size());
            Log.e("*************", newList.size() + "***" + convertDataSixMonth.size() + "*******************");
        } else {
            newList = convertDataSixMonth;
            convertDataSixMonth = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_6MONTH_AGE_VISIT,
                JX_UploadData.TYPE_SIXMONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 八月龄儿童访视
     */
    public void upDataBYLET() {
        List list = new ArrayList<>();
        // 八月龄儿童访视
        List<ChildWithOneYearOld> newList = null;

        if (convertData8Month.size() > subSize) {
            newList = convertData8Month.subList(0, subSize);
            convertData8Month = convertData8Month.subList(subSize, convertData8Month.size());
            Log.e("*************", newList.size() + "***" + convertData8Month.size() + "*******************");
        } else {
            newList = convertData8Month;
            convertData8Month = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_8MONTH_AGE_VISIT,
                JX_UploadData.TYPE_EIGHTMONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 12月龄儿童访视
     */
    public void upDataSeLet() {
        List list = new ArrayList<>();
        // 12月龄儿童访视
        List<MonthsChildHomeVisit> newList = null;

        if (convertData12Month.size() > subSize) {
            newList = convertData12Month.subList(0, subSize);
            convertData12Month = convertData12Month.subList(subSize, convertData12Month.size());
            Log.e("*************", newList.size() + "***" + convertData12Month.size() + "*******************");
        } else {
            newList = convertData12Month;
            convertData12Month = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_12MONTH_AGE_VISIT,
                JX_UploadData.TYPE_12MONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 18月龄儿童访视
     */
    public void upDataSbLet() {
        List list = new ArrayList<>();
        // 18月龄儿童访视
        List<MonthsChildHomeVisit> newList = null;

        if (convertData18Month.size() > subSize) {
            newList = convertData18Month.subList(0, subSize);
            convertData18Month = convertData18Month.subList(subSize, convertData18Month.size());
            Log.e("*************", newList.size() + "***" + convertData18Month.size() + "*******************");
        } else {
            newList = convertData18Month;
            convertData18Month = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_18MONTH_AGE_VISIT,
                JX_UploadData.TYPE_18MONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 24月龄儿童访视
     */
    public void upDataEsLet() {
        List list = new ArrayList<>();
        // 24月龄儿童访视
        List<MonthsChildHomeVisit> newList = null;

        if (convertData24Month.size() > subSize) {
            newList = convertData24Month.subList(0, subSize);
            convertData24Month = convertData24Month.subList(subSize, convertData24Month.size());
            Log.e("*************", newList.size() + "***" + convertData24Month.size() + "*******************");
        } else {
            newList = convertData24Month;
            convertData24Month = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_24MONTH_AGE_VISIT,
                JX_UploadData.TYPE_24MONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 30月龄儿童访视
     */
    public void upDataSsLet() {
        List list = new ArrayList<>();
        // 30月龄儿童访视
        List<MonthsChildHomeVisit> newList = null;

        if (convertData30Month.size() > subSize) {
            newList = convertData30Month.subList(0, subSize);
            convertData30Month = convertData30Month.subList(subSize, convertData30Month.size());
            Log.e("*************", newList.size() + "***" + convertData30Month.size() + "*******************");
        } else {
            newList = convertData30Month;
            convertData30Month = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_30MONTH_AGE_VISIT,
                JX_UploadData.TYPE_30MONTH,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 3岁儿童访视
     */
    public void upData3YearVisitInfo() {
        List list = new ArrayList<>();
        /*  3岁儿童访视*/
        List<YearChildHomeVisit> newList = null;

        if (convertData3Year.size() > subSize) {
            newList = convertData3Year.subList(0, subSize);
            convertData3Year = convertData3Year.subList(subSize, convertData3Year.size());
            Log.e("*************", newList.size() + "***" + convertData3Year.size() + "*******************");
        } else {
            newList = convertData3Year;
            convertData3Year = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_3YEAR_HOME_VISIT,
                JX_UploadData.TYPE_3YEAR,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 4岁儿童访视
     */
    public void upData4YearVisitInfo() {
        List list = new ArrayList<>();
        /*4岁儿童访视*/
        List<YearChildHomeVisit> newList = null;

        if (convertData4Year.size() > subSize) {
            newList = convertData4Year.subList(0, subSize);
            convertData4Year = convertData4Year.subList(subSize, convertData4Year.size());
            Log.e("*************", newList.size() + "***" + convertData4Year.size() + "*******************");
        } else {
            newList = convertData4Year;
            convertData4Year = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_4YEAR_HOME_VISIT,
                JX_UploadData.TYPE_4YEAR,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 5岁儿童访视
     */
    public void upData5YearVisitInfo() {
        List list = new ArrayList<>();
        /*  5岁儿童访视*/
        List<YearChildHomeVisit> newList = null;

        if (convertData5Year.size() > subSize) {
            newList = convertData5Year.subList(0, subSize);
            convertData5Year = convertData5Year.subList(subSize, convertData5Year.size());
            Log.e("*************", newList.size() + "***" + convertData5Year.size() + "*******************");
        } else {
            newList = convertData5Year;
            convertData5Year = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_5YEAR_HOME_VISIT,
                JX_UploadData.TYPE_5YEAR,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 6岁儿童访视
     */
    public void upData6YearVisitInfo() {
        List list = new ArrayList<>();
        // 6岁儿童访视
        List<YearChildHomeVisit> newList = null;

        if (convertData6Year.size() > subSize) {
            newList = convertData6Year.subList(0, subSize);
            convertData6Year = convertData6Year.subList(subSize, convertData6Year.size());
            Log.e("*************", newList.size() + "***" + convertData6Year.size() + "*******************");
        } else {
            newList = convertData6Year;
            convertData6Year = null;
        }

        UploadDataBean udb12 = new UploadDataBean(ModuleName.UPLOAD_CHILD_6YEAR_HOME_VISIT,
                JX_UploadData.TYPE_6YEAR,
                "jsonkey", "addChildhealthChildren", "",
                newList);
        list.add(udb12);
        showProgressDialog(udb12.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 精神病基本信息
     */
    public void updateJSJBInfo() {
        List list = new ArrayList<>();
        // 精神病基本信息
        List<JsjbBaseInfo> newList = null;

        if (converJsjbInfo.size() > subSize) {
            newList = converJsjbInfo.subList(0, subSize);
            converJsjbInfo = converJsjbInfo.subList(subSize, converJsjbInfo.size());
            Log.e("*************", newList.size() + "***" + converJsjbInfo.size() + "*******************");
        } else {
            newList = converJsjbInfo;
            converJsjbInfo = null;
        }

        UploadDataBean udb3 = new UploadDataBean(ModuleName.UPLOAD_JSJB_BASEINFO,
                JX_UploadData.TYPE_JsjbBaseInfo, "MentalJson",
                "addMental", "Jsjb", newList);
        list.add(udb3);
        showProgressDialog(udb3.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 精神病随访
     */
    public void updateJSJBSF() {
        List list = new ArrayList<>();
        // 精神病随访
        List<Jsjbsfb> newList = null;

        if (converJsjbsfb.size() > subSize) {
            newList = converJsjbsfb.subList(0, subSize);
            converJsjbsfb = converJsjbsfb.subList(subSize, converJsjbsfb.size());
            Log.e("*************", newList.size() + "***" + converJsjbsfb.size() + "*******************");
        } else {
            newList = converJsjbsfb;
            converJsjbsfb = null;
        }

        UploadDataBean udb3 = new UploadDataBean(ModuleName.UPLOAD_JSJB_FOLLOWUP,
                JX_UploadData.TYPE_JSJBSF, "MentalJson",
                "addMentalFollowup", "Jsjbsf", newList);
        list.add(udb3);
        showProgressDialog(udb3.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }


    /**
     * 签约用户
     */
    public void upDataQYYH() {

        List list = new ArrayList<>();
        // 签约用户
        List<QyinfoUploadBean> newList = null;

        if (contsQyyh.size() > subSize) {
            newList = contsQyyh.subList(0, subSize);
            contsQyyh = contsQyyh.subList(subSize, contsQyyh.size());
            Log.e("*******upDataQYYH******", newList.size() + "***" + contsQyyh.size() + "*******************");
        } else {
            newList = contsQyyh;
            contsQyyh = null;
        }

        UploadDataBean udb1 = new UploadDataBean(ModuleName.UPLOAD_QYYH, JX_UploadData.TYPE_QYYH, "jsonkey",
                "addCustomerDoctorCont", "", newList);
        list.add(udb1);
        showProgressDialog(udb1.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 服务满意度
     */
    public void upDataFWMYD() {

        List list = new ArrayList<>();
        // 服务满意度
        List<JTYSDoctorEvaluateBean> newList = null;

        if (evaluates.size() > subSize) {
            newList = evaluates.subList(0, subSize);
            evaluates = evaluates.subList(subSize, evaluates.size());
            Log.e("*************", newList.size() + "***" + evaluates.size() + "*******************");
        } else {
            newList = evaluates;
            evaluates = null;
        }

        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPLOAD_FWMYD, JX_UploadData.TYPE_FWMYD, "ServiceSatisJson",
                "addServiceSatis", "", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 履约记录上传
     */
    public void  upDataLvYueJL(){
        List list = new ArrayList<>();
        // 服务满意度
        List<LvYueFuWuBean> newList = null;

        if (lvYueFuWuBeans.size() > subSize) {
            newList = lvYueFuWuBeans.subList(0, subSize);
            lvYueFuWuBeans = lvYueFuWuBeans.subList(subSize, lvYueFuWuBeans.size());
            Log.e("*************", newList.size() + "***" + lvYueFuWuBeans.size() + "*******************");
        } else {
            newList = lvYueFuWuBeans;
            lvYueFuWuBeans = null;
        }
        for(LvYueFuWuBean lvYueFuWuBean:newList){
            if(!TextUtils.isEmpty(lvYueFuWuBean.getHuanQianMingStr())){
                Log.e("患者签名地址",lvYueFuWuBean.getHuanQianMingStr());
                lvYueFuWuBean.setHuanQianMingStr(ImageTools.imageURLToString(lvYueFuWuBean.getHuanQianMingStr()));
            }
            if(!TextUtils.isEmpty(lvYueFuWuBean.getDocQianMingStr())){
                Log.e("医生签名地址",lvYueFuWuBean.getDocQianMingStr());
                lvYueFuWuBean.setDocQianMingStr(ImageTools.imageURLToString(lvYueFuWuBean.getDocQianMingStr()));
            }
            lvYueFuWuBean.setCardNum(TextUtils.isEmpty(lvYueFuWuBean.getCardNum()) ? "" : lvYueFuWuBean.getCardNum().toUpperCase());

        }

        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPLOAD_LVYUEJL, JX_UploadData.TYPE_LVYUEJL, "HyperJson",
                "addPerformance", "", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();
    }

    /**
     * 类风湿数据上传
     */
    public void updateLeiFengshi(){
        List list = new ArrayList<>();
        List<LeiFengShi> newList = null;
        if (leiFengShiFollowups.size() > subSize) {
            newList = leiFengShiFollowups.subList(0, subSize);
            leiFengShiFollowups = leiFengShiFollowups.subList(subSize, leiFengShiFollowups.size());
        } else {
            newList = leiFengShiFollowups;
            leiFengShiFollowups = null;
        }


        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPDATE_LEIFENGSHI, JX_UploadData.TYPE_LEIFENGSHI, "LfsJson",
                "addLfs", "", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();


    }

    /**
     * 肺心病数据上传
     */
    public void updateFeiXinBing(){
        List list = new ArrayList<>();
        List<FeiXinBing> newList = null;
        if (feiXinBingFollowups.size() > subSize) {
            newList = feiXinBingFollowups.subList(0, subSize);

            feiXinBingFollowups = feiXinBingFollowups.subList(subSize, feiXinBingFollowups.size());
        } else {
            newList = feiXinBingFollowups;
            feiXinBingFollowups = null;
        }


        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPLOAD_FEIXINBING, JX_UploadData.TYPE_FEIXINBING, "FxbJson",
                "addFxb", "", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();


    }
    /**
     *风湿病数据上传
     */
    public void updateFengShiBing(){
        List list = new ArrayList<>();
        List<FengShiBing> newList = null;
        if (fengShiBingFollowups.size() > subSize) {
            newList = fengShiBingFollowups.subList(0, subSize);
            fengShiBingFollowups = fengShiBingFollowups.subList(subSize, fengShiBingFollowups.size());
        } else {
            newList = fengShiBingFollowups;
            fengShiBingFollowups = null;
        }


        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPDATE_FENGSHIBING, JX_UploadData.TYPE_FENGSHIBING, "FsbJson",
                "addFsb", "", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();


    }

    /**
     *慢阻肺数据上传
     */
    public void updateManZuFei(){
        List list = new ArrayList<>();
        List<ManZuFei> newList = null;
        if (manZuFeiFollowups.size() > subSize) {
            newList = manZuFeiFollowups.subList(0, subSize);
            manZuFeiFollowups = manZuFeiFollowups.subList(subSize, manZuFeiFollowups.size());
        } else {
            newList = manZuFeiFollowups;
            manZuFeiFollowups = null;
        }


        UploadDataBean udb2 = new UploadDataBean(ModuleName.UPDATE_MANZUFEI, JX_UploadData.TYPE_MANZUFEI, "MzfJson",
                "addMzf", "", newList);
        list.add(udb2);
        showProgressDialog(udb2.getDataName() + "数据正在上传中，请稍候...");
        UploadDatas uld = new UploadDatas(DataDownLoadMainActivity.this, list);
        uld.uploadDatas();


    }




    public void getHandler() {
        Manager.getInstance().setHandler(handler);
    }

    /**
     * 没有token值时重新获取token值
     */
    private void getToken() {

        try {
            new ZCMWebService(mContext) {

                @Override
                public void start(String message) {
                    super.start(message);
                }

                @Override
                public void onSynchronize(String message, int syncCount, int dataSize) {
                    super.onSynchronize(message, syncCount, dataSize);
                }

                @Override
                public void complete(final String message) {
                    super.complete(message);
                    cancelProgressDialog();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            String token = SPUtil.getToken(mContext);
                            if (TextUtils.isEmpty(token)) {
                                resultDialog.setText("获取token失败,请重试!");
                                resultDialog.showCancleLong();
                                return;
                            }

                        }
                    });
                }

                @Override
                public void onError(String message) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            resultDialog.setText("获取token失败,请检查上传地址是否有误！");
                            resultDialog.showCancleLong();

                        }
                    });
                    return;
                }

                ;
            }.synchrodata(NovaApplication.getImei());
        } catch (Exception e) {
            e.printStackTrace();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    resultDialog.setText("获取token失败,请检查上传地址是否有误！");
                    resultDialog.showCancleLong();

                }
            });
            return;
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_back:
                finish();
                break;

            default:
                break;
        }

    }


    /**
     * 数据上传【家庭签约用户数据】
     *
     * @author 王婷婷
     * @date 2017年7月17日 下午7:27:43
     */
    private void getDataUp() {
        startCJDA();
    }

    /**
     * 签约服务
     */

    Runnable runnable1 = new Runnable() {

        @Override
        public void run() {// run()在新的线程中运行
            try {
                okHttp_postFromParameters();
            } catch (Exception e) {
                e.printStackTrace();
                mHandler.sendEmptyMessage(0x07);
                return;
            }
        }
    };
    /**
     * 满意度
     */

    Runnable runnable2 = new Runnable() {

        @Override
        public void run() {// run()在新的线程中运行
            try {
                okHttp_postFromParameters_fwmydpj();
            } catch (Exception e) {
                e.printStackTrace();
                // mHandler.sendEmptyMessage(NO_DATA);
                mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
                return;
            }
        }
    };
    /**
     * 创建用户
     */
    Runnable runnable3 = new Runnable() {

        @Override
        public void run() {// run()在新的线程中运行
            try {
                okHttp_postFromParameters_CJYH();
            } catch (Exception e) {
                e.printStackTrace();
                mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
                return;
            }
        }
    };

    private void downloadJtqyyh() {
        try {
            String url = GlobalContsJTYS.getUrlPost_JTYS() + GetPostJTYS.URL_JTYS_XZQYSJ + "/";
            OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(100, TimeUnit.SECONDS)
                    .writeTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS);
            OkHttpClient okHttpClient = builder.build();
            // OkHttpClient okHttpClient = new OkHttpClient();
            String str_jdrUserName = SPUtil.getStr_jdrno(DataDownLoadMainActivity.this);
            System.out.println(url + "?" + "qyys=" + str_jdrUserName + "&officeId=" + NovaApplication.getJgbh());
            RequestBody formBody = new FormBody.Builder().add("qyys", str_jdrUserName)
                    .add("officeId", NovaApplication.getJgbh()).build();
            Request request = new Request.Builder().url(url).post(formBody).build();
            okhttp3.Response response = okHttpClient.newCall(request).execute();
            JSONObject obj;

            String result = response.body().string();
            obj = new JSONObject(result.toString());
            System.out.println("返回的obje" + result);
            if (obj.has("success")) {
                if (obj.getBoolean("success")) {
                    if (obj.has("infor")) {
                        String infor = obj.getString("infor");
                        List<JTYSCustomerDoctorCont> users = new Gson().fromJson(infor,
                                new TypeToken<List<JTYSCustomerDoctorCont>>() {
                                }.getType());
                        List<JTYSCustomerDoctorCont> locDatas = NovaApplication.fdbmanger
                                .findAll(JTYSCustomerDoctorCont.class);
                        Map<String, JTYSCustomerDoctorCont> dataMap = new HashMap<>();
                        for (JTYSCustomerDoctorCont data : locDatas) {
                            dataMap.put(data.getId(), data);
                        }
                        // 2017-03-14 17:40:21
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        for (JTYSCustomerDoctorCont jtys : users) {
                            if (dataMap.containsKey(jtys.getId())) {
                                try {
                                    if (sdf.parse(dataMap.get(jtys.getId()).getUpdatedate())
                                            .after(sdf.parse(dataMap.get(jtys.getId()).getUpdatedate()))) {
                                        NovaApplication.fdbmanger.save(jtys);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            } else {
                                NovaApplication.fdbmanger.save(jtys);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 家庭签约医生数据上传
     */

    private void okHttp_postFromParameters() {
        // new Thread(new Runnable() {
        // @Override
        // public void run() {
        try {
            List<JTYSCustomerDoctorCont> conts = NovaApplication.fdbmanger.findAllByWhere(JTYSCustomerDoctorCont.class,
                    "CREATER='" + SPUtil.getstr_jdrusername(DataDownLoadMainActivity.this) + "' AND SIGN!='1'");
            List<JTYSCustomerDoctorCont> conts1 = NovaApplication.fdbmanger.findAllByWhere(JTYSCustomerDoctorCont.class,
                    "CREATER='" + SPUtil.getStr_jdrno(DataDownLoadMainActivity.this) + "' AND SIGN!='1'");
            if(conts1.size()>0){
                conts.addAll(conts1);
            }
            if (conts.size() > 0) {

            } else {
                mHandler.sendEmptyMessage(0x06);
                return;
            }
            String json = new Gson().toJson(conts);

            // 请求完整url：http://api.k780.com:88/?app=weather.future&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json
            String url = GlobalContsJTYS.getUrlPost_JTYS() + GetPostJTYS.URL_JTYS_SCQYSJ + "/";
            System.out.println("签约用户接口" + url + "?jsonkey=" + json);
            // OkHttpClient okHttpClient = new OkHttpClient();
            OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(100, TimeUnit.SECONDS)
                    .writeTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS);
            OkHttpClient okHttpClient = builder.build();

            RequestBody formBody = new FormBody.Builder().add("jsonkey", json).build();
            Request request = new Request.Builder().url(url).post(formBody).build();
            okhttp3.Response response = okHttpClient.newCall(request).execute();
            // Log.i(TAG, "接口返回的 的的" + response.body().string());
            String result = response.body().string();
            System.out.println("签约用户接口返回" + result);

            UpDataReturn updata = JX_SJSC.jxJTQYYSData(result);
            if (updata != null) {
                sumSize1 = updata.getSize();
                successCount1 = updata.getSuccessCount();
                failCount1 = updata.getFailCount();
                Log.e("tag", sumSize1 + "sumSize1" + successCount1 + "successCount1" + failCount1 + "failCount1");
            } else {
                cleanData();
            }
            mHandler.sendEmptyMessage(0x06);
        } catch (Exception e) {
            mHandler.sendEmptyMessage(0x07);
            e.printStackTrace();
        }

    }

    /**
     * 服务满意度评价
     *
     * @author 王婷婷
     * @date 2017年6月5日 下午2:24:17
     */
    private void okHttp_postFromParameters_fwmydpj() {
        try {
            List<JTYSDoctorEvaluateBean> conts = NovaApplication.fdbmanger.findAllByWhere(JTYSDoctorEvaluateBean.class,
                    "CREATER='" + NovaApplication.getJgrno() + "' AND SIGN ='0'");
            if (conts.size() > 0) {

            } else {
                mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
                return;
            }
            String json = new Gson().toJson(conts);

            // 请求完整url：http://api.k780.com:88/?app=weather.future&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json
            String url = GlobalContsJTYS.getUrlPost_JTYS() + GetPostJTYS.URL_JTYS_FWMYDPJ + "/";
            System.out.println("服务满意度" + url + "?jsonkey=" + json);

            OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(100, TimeUnit.SECONDS)
                    .writeTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS);
            OkHttpClient okHttpClient = builder.build();
            // OkHttpClient okHttpClient = new OkHttpClient();
            RequestBody formBody = new FormBody.Builder().add("jsonkey", json).build();
            Request request = new Request.Builder().url(url).post(formBody).build();
            okhttp3.Response response = okHttpClient.newCall(request).execute();
            UpDataReturn updata = JX_SJSC.jxFwmydData(response.body().string());
            if (updata != null) {
                sumSize2 = updata.getSize();
                successCount2 = updata.getSuccessCount();
                failCount2 = updata.getFailCount();
                Log.e("tag", sumSize2 + "sumSize2" + successCount2 + "successCount2" + failCount2 + "failCount2");
            } else {
                cleanData();
            }
            mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
        } catch (Exception e) {
            mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
            e.printStackTrace();
        }

    }

    /**
     * 创建用户上传
     *
     * @author 王婷婷
     * @date 2017年6月5日 下午2:24:17
     */
    private void okHttp_postFromParameters_CJYH() {
        try {
            List<JTYS_BASEINFO> conts = NovaApplication.fdbmanger.findAllByWhere(JTYS_BASEINFO.class,
                    "CREATER='" + NovaApplication.getJgrno() + "' AND SIGN ='0'");

            if (conts.size() > 0) {

            } else {
                mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
                return;
            }

            String json = new Gson().toJson(conts);
            String url = GlobalContsJTYS.getUrlPost_JTYS() + GetPostJTYS.URL_JTYS_CJDA_LIST;
            System.out.println(url + "?jsonkey=" + json);
            OkHttpClient okHttpClient = new OkHttpClient();
            RequestBody formBody = new FormBody.Builder().add("jsonkey", json).build();
            Request request = new Request.Builder().url(url).post(formBody).build();
            okhttp3.Response response = okHttpClient.newCall(request).execute();
            // Log.i(TAG, "接口返回的 的的" + response.body().string());
            UpDataReturn updata = JX_SJSC.jxCJYHData(response.body().string());
            if (updata != null) {
                sumSize0 = updata.getSize();
                successCount0 = updata.getSuccessCount();
                failCount0 = updata.getFailCount();
                errorMsg0 = updata.getErrMsg();
                failCountYcz0 = updata.getFailCountYcz();
            } else {
                cleanData();
            }
            mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
        } catch (Exception e) {
            mHandler.sendEmptyMessage(UPLOAD_MEASUREMENT_DATA);
            e.printStackTrace();
        }
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {// 此方法在ui线程运行
            switch (msg.what) {
                case DOWNLOAD_OVER:
                    if (resultDialog == null) {
                        resultDialog = new ResultTextDialog(DataDownLoadMainActivity.this);
                    }
                    resultDialog.setText("下载数据总共" + sumSize + "条,保存成功" + successCount + "条,保存失败" + failCount + "条。");
                    resultDialog.showCancleLong();
                    break;
                case UPLOAD_FWMYD:
                    startQYys();
                    break;
                case NO_DATA:
                    if (resultDialog == null) {
                        resultDialog = new ResultTextDialog(DataDownLoadMainActivity.this);
                    }
                    resultDialog.setText("暂无数据上传");
                    resultDialog.showCancleShort();
                    break;
                case SHOW_UPLOAD_RESULT:
                    showUpLoadDataResult();
                    break;
                case UPLOAD_FUMYD2:
                    startQYys();
                    break;
                case 0x06:// 666
                    startFwmyd();
                    break;
                case 0x07:// 666
                    startFwmyd();
                    break;
                case UPLOAD_MEASUREMENT_DATA:
                    cancelProgressDialog();
                    startMeasurementData();
                    break;
            }
        }

    };

    private void cleanData() {
        sumSize = 0;
        successCount = 0;
        failCount = 0;

        sumSize0 = 0;
        successCount0 = 0;
        failCount0 = 0;
        errorMsg0 = "";
        failCountYcz0 = 0;

        sumSize1 = 0;
        successCount1 = 0;
        failCount1 = 0;

        sumSize2 = 0;
        successCount2 = 0;
        failCount2 = 0;

        sumSize3 = 0;
        successCount3 = 0;
        failCount3 = 0;
    }

    @Override
    public void setListeners() {

    }

    /**
     * 测量数据历史上传
     */
    private void startMeasurementData() {

        new Thread(runnable4).start();

    }

    Runnable runnable4 = new Runnable() {

        @Override
        public void run() {

            okHttp_postFromParameters_MeasurementData();
        }
    };

    protected void okHttp_postFromParameters_MeasurementData() {
        try {
            List<MeasurementData> dataList = MeasurementData.converData().getDataList();
            if (dataList.size() == 0) {
                mHandler.sendEmptyMessage(SHOW_UPLOAD_RESULT);
                return;
            }


            String json = new Gson().toJson(dataList);

            // 请求完整url：http://api.k780.com:88/?app=weather.future&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json
            String url = GlobalContsJTYS.getUrlPost_JTYS() + GetPostJTYS.URL_JTYS_MEASURE_DATA;// TODO:需要修改
            // String url = "" + GetPostJTYS.URL_JTYS_MEASURE_DATA;// TODO:需要修改
            System.out.println("测量数据接口" + url + "?jsonkey=" + json);
            // OkHttpClient okHttpClient = new OkHttpClient();
            OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(100, TimeUnit.SECONDS)
                    .writeTimeout(30, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS);
            OkHttpClient okHttpClient = builder.build();

            RequestBody formBody = new FormBody.Builder().add("jsonkey", json).build();
            Request request = new Request.Builder().url(url).post(formBody).build();
            okhttp3.Response response = okHttpClient.newCall(request).execute();
            // Log.i(TAG, "接口返回的 的的" + response.body().string());
            String result = response.body().string();
            System.out.println("测量数据接口返回" + result);

            UpDataReturn updata = JX_SJSC.jxMeasureDataHistoryData(result);
            if (updata != null) {
                sumSize3 = updata.getSize();
                successCount3 = updata.getSuccessCount();
                failCount3 = updata.getFailCount();
                Log.e("tag", sumSize3 + "sumSize3" + successCount3 + "successCount3" + failCount3 + "failCount3");
            } else {
                cleanData();
            }
            mHandler.sendEmptyMessage(SHOW_UPLOAD_RESULT);
        } catch (Exception e) {
            mHandler.sendEmptyMessage(SHOW_UPLOAD_RESULT);
            e.printStackTrace();
        }

    }

    /**
     * 服务满意度数据上传
     *
     * @author 王婷婷
     * @date 2017年7月17日 下午7:50:28
     */
    private void startFwmyd() {

        List<JTYSDoctorEvaluateBean> conts = NovaApplication.fdbmanger.findAllByWhere(JTYSDoctorEvaluateBean.class,
                "CREATER='" + NovaApplication.getJgrno() + "' AND SIGN ='0'");
        if (conts.size() == 0) {
            // showUpLoadDataResult();
            startMeasurementData();
            return;
        }

        new Thread(runnable2).start();
    }

    /**
     * 服务满意度数据上传
     *
     * @author 王婷婷
     * @date 2017年7月17日 下午7:50:28
     */
    private void startQYys() {
        List<JTYSCustomerDoctorCont> conts = NovaApplication.fdbmanger.findAllByWhere(JTYSCustomerDoctorCont.class,
                "CREATER='" + SPUtil.getstr_jdrusername(DataDownLoadMainActivity.this) + "' AND SIGN!='1'");
        List<JTYSCustomerDoctorCont> conts1 = NovaApplication.fdbmanger.findAllByWhere(JTYSCustomerDoctorCont.class,
                "CREATER='" + SPUtil.getStr_jdrno(DataDownLoadMainActivity.this) + "' AND SIGN!='1'");
        if(conts1.size()>0){
            conts.addAll(conts1);
        }

        if (conts.size() == 0) {
            startFwmyd();
            return;
        }

        new Thread(runnable1).start();
    }

    /**
     * 创建档案
     *
     * @author 王婷婷
     * @date 2017年7月17日 下午7:50:28
     */
    private void startCJDA() {
        List<JTYS_BASEINFO> conts = NovaApplication.fdbmanger.findAllByWhere(JTYS_BASEINFO.class,
                "CREATER='" + NovaApplication.getJgrno() + "' AND SIGN ='0'");

        if (conts.size() == 0) {
            startMeasurementData();
            return;
        }else{
           showProgressDialog("测量数据正在上传中，请稍候");
        }

        new Thread(runnable3).start();
    }

    /**
     * 显示数据返回结果
     *
     * @author 王婷婷
     * @date 2017年7月17日 下午8:04:03
     */
    private void showUpLoadDataResult() {
        if (resultDialog == null) {
            resultDialog = new ResultTextDialog(DataDownLoadMainActivity.this);
        }
        if (sumSize0 != 0 || sumSize1 != 0 || sumSize2 != 0 || sumSize3 != 0) {

            String str_jdyhDataReturn = "建档用户  上传数据总共" + sumSize0 + "条,上传成功" + successCount0 + "条,上传失败" + failCount0
                    + "条,已存在 " + failCountYcz0 + "条。" + (TextUtils.isEmpty(errorMsg0) ? "" : "\n" + errorMsg0);
            //+ "签约用户  上传数据总共" + sumSize1 + "条,上传成功" + successCount1+ "条,上传失败" + failCount1 + "条。\n" + "服务满意度  上传数据总共" + sumSize2 + "条,上传成功" + successCount2 + "条,上传失败"+ failCount2 + "条。\n"
            resultDialog.setText(str_jdyhDataReturn + "\n" + "测量数据  上传数据总共" + sumSize3 + "条,上传成功" + successCount3 + "条,上传失败" + failCount3 + "条。");
            resultDialog.showCancleLong();
        } else {
            resultDialog.setText("暂无数据上传");
            resultDialog.showCancleShort();
        }
    }

    /**
     * 检查Token是否存在
     */
    private boolean checkToken() {
        boolean flag = true;
        if (!SPUtil.getIsShiYong(mContext)) {
            //不是试用状态
            flag = false;
        }
        return flag;
    }


    /**
     * 进行数据上传
     */
    private void upNextData(String type) {
        switch (type) {
            case ModuleName.UPLOAD_SELFINFO:
                //个人基本信息：
                if (convertDataInfo != null && convertDataInfo.size() > 0) {
                    upDataJBXX();
                    break;
                }
            case ModuleName.UPLOAD_TNB:
                //糖尿病：
                if (convertDataTnb != null && convertDataTnb.size() > 0) {
                    upDataTNB();
                    break;
                }
            case ModuleName.UPLOAD_TNB_DYCSF:
                //肺结核第一次随访：
                if (convertDataFjhBaseInfo != null && convertDataFjhBaseInfo.size() > 0) {
                    upDataFjhDycsf();
                    break;
                }
            case ModuleName.UPLOAD_TNB_SFXX:
                //肺结核随访信息：
                if (convertDataFjhFollowUpInfo != null && convertDataFjhFollowUpInfo.size() > 0) {
                    upDataFjhSfxx();
                    break;
                }
            case ModuleName.UPLOAD_NCZ:
                //脑卒中
                if (convertDataNCZ != null && convertDataNCZ.size() > 0) {
                    updateNCZ();
                    break;
                }
            case ModuleName.UPLOAD_GXB:
                //冠心病：
                if (convertDataGXB != null && convertDataGXB.size() > 0) {
                    updateGXB();
                    break;
                }

            case ModuleName.UPLOAD_GXY:
                //高血压：
                if (convertDataGxy != null && convertDataGxy.size() > 0) {
                    updateGXY();
                    break;
                }
            case ModuleName.UPLOAD_HEALTH_EXAMINATION:
                //健康体检
                if (convertDataJktj != null && convertDataJktj.size() > 0) {
                    updaTaJKTJ();
                    break;
                }
            case ModuleName.UPLOAD_ELDERLY_MEDICINE:
                //老年人中医体质
                if (convertDataLnrzyy != null && convertDataLnrzyy.size() > 0) {
                    upDataLNRZYY();
                    break;
                }
            case ModuleName.UPLOAD_ELDERLY_SELFCARE_ABILITY:
                //老年人自理能力
                if (convertDataLnrzlnl != null && convertDataLnrzlnl.size() > 0) {
                    upDataLNRZLNL();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_NEWBORN_VISITS:
                //新生儿访视
                if (convertDataXSRFS != null && convertDataXSRFS.size() > 0) {
                    upDataXSEFS();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_1MONTH_AGE_VISIT:
                //满月龄儿童访视
                if (convertDataOneMonth != null && convertDataOneMonth.size() > 0) {
                    upDataMYLET();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_3MONTH_AGE_VISIT:
                //三月龄儿童访视
                if (convertDataThreeMonth != null && convertDataThreeMonth.size() > 0) {
                    upDataSYLET();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_6MONTH_AGE_VISIT:
                //六月龄儿童访视
                if (convertDataSixMonth != null && convertDataSixMonth.size() > 0) {
                    upDataLYLET();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_8MONTH_AGE_VISIT:
                //8月龄儿童访视
                if (convertData8Month != null && convertData8Month.size() > 0) {
                    upDataBYLET();
                    break;
                }
            case ModuleName.UPLOAD_CHILD_12MONTH_AGE_VISIT:
                //12月龄儿童家庭访视
                if (convertData12Month != null && convertData12Month.size() > 0) {
                    upDataSeLet();
                    break;
                }


            case ModuleName.UPLOAD_CHILD_18MONTH_AGE_VISIT:
                //18月龄儿童家庭访视
                if (convertData18Month != null && convertData18Month.size() > 0) {
                    upDataSbLet();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_24MONTH_AGE_VISIT:
                //24月龄儿童家庭访视
                if (convertData24Month != null && convertData24Month.size() > 0) {
                    upDataEsLet();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_30MONTH_AGE_VISIT:
                //30月龄儿童家庭访视
                if (convertData30Month != null && convertData30Month.size() > 0) {
                    upDataSsLet();
                    break;
                }
            case ModuleName.UPLOAD_CHILD_3YEAR_HOME_VISIT:
                //3岁儿童家庭访视
                if (convertData3Year != null && convertData3Year.size() > 0) {
                    upData3YearVisitInfo();
                    break;
                }
            case ModuleName.UPLOAD_CHILD_4YEAR_HOME_VISIT:
                //4岁儿童家庭访视
                if (convertData4Year != null && convertData4Year.size() > 0) {
                    upData4YearVisitInfo();
                    break;
                }
            case ModuleName.UPLOAD_CHILD_5YEAR_HOME_VISIT:
                //5岁儿童家庭访视
                if (convertData5Year != null && convertData5Year.size() > 0) {
                    upData5YearVisitInfo();
                    break;
                }

            case ModuleName.UPLOAD_CHILD_6YEAR_HOME_VISIT:
                //6岁儿童家庭访视
                if (convertData6Year != null && convertData6Year.size() > 0) {
                    upData6YearVisitInfo();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_1TIMES_PRENATAL_VISIT:
                /* 第一次产前访视*/
                if (convertDataTheFirstTimePrenatalVisit != null && convertDataTheFirstTimePrenatalVisit.size() > 0) {
                    upDataFirstPrenatalVisit();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_2TIMES_PRENATAL_VISIT:
                /* 第二次产前访视*/
                if (convertData2TimesPrenatalVisits != null && convertData2TimesPrenatalVisits.size() > 0) {
                    upDataSecondPrenatalVisits();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_3TIMES_PRENATAL_VISIT:
                /* 第三次产前访视*/
                if (convertData3TimesPrenatalVisits != null && convertData3TimesPrenatalVisits.size() > 0) {
                    upDataThirdPrenatalVisits();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_4TIMES_PRENATAL_VISIT:
                /* 第四次产前访视*/
                if (convertData4TimesPrenatalVisits != null && convertData4TimesPrenatalVisits.size() > 0) {
                    upDataFourTimesPrenatalVisits();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_5TIMES_PRENATAL_VISIT:
                /* 第五次产前访视*/
                if (convertData5TimesPrenatalVisits != null && convertData5TimesPrenatalVisits.size() > 0) {
                    upDataFiveTimesPrenatalVisits();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_MATERNAL_POSTNATAL_VISITS:
                /* 孕产妇产后访视*/
                if (convertDataMaternalPostnatalVisits != null && convertDataMaternalPostnatalVisits.size() > 0) {
                    upDataPostnatalVisitsPrenatalVisits();
                    break;
                }
            case ModuleName.UPLOAD_PREGNANT_MATERNAL_42DAYS_VISITS:
                /* 孕产妇产后42天健康检查*/
                if (convertDataMaternalFortyTwoDaysVisits != null && convertDataMaternalFortyTwoDaysVisits.size() > 0) {
                    upData42DaysPrenatalVisits();
                    break;
                }
            case ModuleName.UPLOAD_JSJB_BASEINFO:
                /* 精神病基本信息*/
                if (converJsjbInfo != null && converJsjbInfo.size() > 0) {
                    updateJSJBInfo();
                    break;
                }
            case ModuleName.UPLOAD_JSJB_FOLLOWUP:
                /* 精神病随访*/
                if (converJsjbsfb != null && converJsjbsfb.size() > 0) {
                    updateJSJBSF();
                    break;
                }
            case ModuleName.UPLOAD_QYYH:
                /* 签约用户*/
                if (contsQyyh != null && contsQyyh.size() > 0) {
                    upDataQYYH();
                    break;
                }
            case ModuleName.UPLOAD_FWMYD:
                /* 服务满意度用户*/
                if (evaluates != null && evaluates.size() > 0) {
                    upDataFWMYD();
                    break;
                }
            case ModuleName.UPLOAD_PHOTO:
                /* 照片*/
                if (pictures != null && pictures.size() > 0) {
                    upDataPhoto();
                    break;
                }
            case ModuleName.UPLOAD_LVYUEJL:
                if(lvYueFuWuBeans!=null&&lvYueFuWuBeans.size()>0){
                    upDataLvYueJL();
                    break;
                }
            case ModuleName.UPLOAD_FEIXINBING:
                if(feiXinBingFollowups!=null&&feiXinBingFollowups.size()>0){
                    updateFeiXinBing();
                    break;
                }
            case ModuleName.UPDATE_LEIFENGSHI:
                if(leiFengShiFollowups!=null&&leiFengShiFollowups.size()>0){
                    updateLeiFengshi();
                    break;
                }
            case ModuleName.UPDATE_FENGSHIBING:
                if(fengShiBingFollowups!=null&&fengShiBingFollowups.size()>0){
                    updateFengShiBing();
                    break;
                }
            case ModuleName.UPDATE_MANZUFEI:
                if(manZuFeiFollowups!=null&&manZuFeiFollowups.size()>0){
                    updateManZuFei();
                    break;
                }
            default:
                break;

        }
    }

    public void updata_SBCL(){
        showProgressDialog("正在上传，请稍候");
        //启动后台异步线程进行连接webService操作，并且根据返回结果在主线程中改变UI
        QueryAddressTask queryAddressTask = new QueryAddressTask();
        //启动后台任务
        queryAddressTask.execute();
    }
    String result;
    /**
     * 手机号段归属地查询
     *
     *
     */
    public String getRemoteInfo() throws Exception{
        String WSDL_URI = GlobalConts.getUrlPost()+"webservice/UploadService/addEquipment";//wsdl 的uri
        String namespace = "http://webservice.yide.com/";//namespace
        String methodName = "addEquipment";//要调用的方法名称
        List<MeasurementDataNew> dataList = MeasurementDataNew.converData().getDataList();
        Gson gson = new Gson();
        SoapObject request = new SoapObject(namespace, methodName);
        // 设置需调用WebService接口需要传入的两个参数mobileCode、userId
        String json=gson.toJson(dataList);
        Log.e("***测量数据",json);
        request.addProperty("EquipmentJson", json);


        //创建SoapSerializationEnvelope 对象，同时指定soap版本号(之前在wsdl中看到的)
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER10);
        envelope.bodyOut = request;//由于是发送请求，所以是设置bodyOut
//        envelope.dotNet = true;//由于是.net开发的webservice，所以这里要设置为true

        HttpTransportSE httpTransportSE = new HttpTransportSE(WSDL_URI);
        httpTransportSE.call(null, envelope);//调用

        // 获取返回的数据
        SoapObject object = (SoapObject) envelope.bodyIn;
        // 获取返回的结果
        result = object.getProperty(0).toString();
        Log.d("debug",result);
        return result;

    }

    class QueryAddressTask extends AsyncTask<String, Integer, String> {
        @Override
        protected String doInBackground(String... params) {
            // 查询手机号码（段）信息*/
            try {
                result = getRemoteInfo();

            } catch (Exception e) {
                e.printStackTrace();
            }
            //将结果返回给onPostExecute方法
            return result;
        }

        @Override
        //此方法可以在主线程改变UI
        protected void onPostExecute(String result) {
            // 将WebService返回的结果显示在TextView中
            if(!TextUtils.isEmpty(result)){

//                JSONArray jsarray= null;
//                int i1 = 0;
//                int i2 = 0;
//                try {
//                    jsarray = new JSONArray(result);
//                    if(jsarray.length()>0){
//                        for (int i = 0; i < jsarray.length(); i++) {
//                            JSONObject obj = jsarray.getJSONObject(i);
//                            String state = obj.getString("state");
//                            if(state.equals("000")){
//                                i1++;
//                            }else{
//                                i2++;
//                            }
//                        }
//                    }
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
                showTextDialog("上传完成");

                List<SBCL_DATA> list = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class,"IS_UPDATE is not 'N'" ,
                        "CL_TIME desc");
                if(list.size()>0){
                    for(SBCL_DATA sbcl_data:list){
                        sbcl_data.setIS_UPDATE("N");
                        NovaApplication.fdbmanger.updata(sbcl_data);
                    }
                }

                cancelProgressDialog();
                Log.e("*********",result);
            }else{
                showTextDialog("网络不给力");
                cancelProgressDialog();
            }

        }
    }


    //上传随访数据
    private static final int START_REQUEST = 1001;
    private static final int COM_REQUEST = 1002;
    //上传档案数据
    private static final int UPLOAD_ARCHIVES = 1003;

    private int totalSize = 0;
    private int successSize = 0;
    private int errorSize = 0;

    private int totalArchivesSize = 0;
    private int successArchivesSize = 0;
    private int errorArchivesSize = 0;

    private int totalArchivesSizeNew = 0;
    private int successArchivesSizeNew = 0;
    private int errorArchivesSizeNew = 0;

    private int totalSbclDataSizeNew = 0;
    private int successSbclDataSizeNew = 0;
    private int errorSbclDataSizeNew = 0;
    /**
     * 随访表上传完 之后调用一次
     */
    private void sendFollowTable() {
//        String doctorId = SPUtils.getInstance().getString(HttpConstant._DOCTOR_ID,"");
        Log.e("当前医生", NovaApplication.getJgrno());

//        RxHttp.postForm(HttpConstant.sendFollowTable + NovaApplication.getJgrno())
//                .asString()
//                .subscribe(resultBean -> {
//                    Log.e("xiaoxin", "sendFollowTable: 11" );
//                }, throwable -> {
//                    Log.e("xiaoxin", "sendFollowTable:22 " );
//                });
    }
    private Handler uploadHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            int position = Integer.parseInt(msg.obj.toString());
            Log.e(TAG, "position: " + position );
            switch (msg.what) {
                case START_REQUEST:
                    if (position < objectList.size()) {
                        showProgressDialog("随访数据" + objectList.size() + "条记录,上传成功"
                                + successSize + "条记录,上传失败" + errorSize +"条记录");
                        totalSize++;
                        request(position);
                    } else {
                        cancelProgressDialog();
                        showTextDialog("随访数据" + objectList.size() + "条记录,上传成功"
                                + successSize + "条记录,上传失败" + errorSize +"条记录");
//                        sendFollowTable();
                    }
                    break;
                case COM_REQUEST:
                    break;
                case UPLOAD_ARCHIVES:
                    if (position < archiveBaseinfos.size()) {
                        showProgressDialog("档案数据" +archiveBaseinfos.size() + "条记录,上传成功"
                                + successArchivesSize + "条记录,上传失败" + errorArchivesSize +"条记录");
                        totalArchivesSize++;
                        requestArchive(archiveBaseinfos.get(position),position);
                    } else {
                        cancelProgressDialog();
                        showTextDialog("档案数据" + archiveBaseinfos.size() + "条记录,上传成功"
                                + successArchivesSize + "条记录,上传失败" + errorArchivesSize +"条记录");
                    }
                    break;
                case UPLOAD_ARCHIVES_NEW:
                    if (position < archiveBaseinfosNew.size()) {
                        showProgressDialog("档案数据" +archiveBaseinfosNew.size() + "条记录,上传成功"
                                + successArchivesSizeNew + "条记录,上传失败" + errorArchivesSizeNew +"条记录");
                        totalArchivesSizeNew++;
                        requestArchiveNew(archiveBaseinfosNew.get(position),position);
                    } else {
                        cancelProgressDialog();
                        showTextDialog("档案数据" + archiveBaseinfosNew.size() + "条记录,上传成功"
                                + successArchivesSizeNew + "条记录,上传失败" + errorArchivesSizeNew +"条记录");
                    }
                    break;
                case UPLOAD_SBCLDATA_NEW:
                    if (position < sbclDataNewList.size()) {
                        showProgressDialog("体检数据" +sbclDataNewList.size() + "条记录,上传成功"
                                + successSbclDataSizeNew + "条记录,上传失败" + errorSbclDataSizeNew +"条记录");
                        totalSbclDataSizeNew++;
                        requestSbclDataNew(sbclDataNewList.get(position),position);
                    } else {
                        cancelProgressDialog();
                        showTextDialog("体检数据" + sbclDataNewList.size() + "条记录,上传成功"
                                + successSbclDataSizeNew + "条记录,上传失败" + errorSbclDataSizeNew +"条记录");
                    }
                    break;
            }
        }
    };

//    private void request(int position) {
//        if (position >= objectList.size()) return;
//        HttpDataBean httpDataBean = new HttpDataBean();
//        String orgCold = NovaApplication.getDoctorGBcode() + "0000000000000";
//        httpDataBean.OrgCold =orgCold.substring(0,12);
//        if (objectList.get(position) instanceof CD_HYPERTENSIONFOLLOWUP) {
//            Log.e(TAG, "高血压: " );
//            String json = AssetUtil.getJson("GxySymptom.json", NovaApplication.getInstance());
//            List<BD_DD_INFO> list = GsonUtils.fromJson(json, new TypeToken<List<BD_DD_INFO>>() {}.getType());
//            httpDataBean.QueryType = QueryTypeEnum.GXY.getCode();
//            httpDataBean.Data = mGson.toJson(FormatGxyData.formatGxy((CD_HYPERTENSIONFOLLOWUP)objectList.get(position),list));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
//        } else if (objectList.get(position) instanceof CD_DIABETESFOLLOWUP) {
//            Log.e(TAG, "糖尿病: " );
//            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
//                    "PARENTID='DM04-03'");
////            HttpDataBean httpDataBean = new HttpDataBean();
//            httpDataBean.QueryType = QueryTypeEnum.TNB.getCode();
//            httpDataBean.Data = mGson.toJson(FormatTnbData.formatGxy((CD_DIABETESFOLLOWUP)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
//        } else if (objectList.get(position) instanceof CD_MENTALDISEASE_FOLLOWUP) {
//            Log.e(TAG, "jsb: " );
//            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
//                    "PARENTID='DM07-01'");
////            HttpDataBean httpDataBean = new HttpDataBean();
//            httpDataBean.QueryType = QueryTypeEnum.JSB.getCode();
//            httpDataBean.Data = mGson.toJson(FormatJsbData.formatJsb((CD_MENTALDISEASE_FOLLOWUP)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
//        } else if (objectList.get(position) instanceof CD_TUBERCULOSIS_FOLLOWUP) {
//            Log.e(TAG, "肺结核: " );
//            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
//                    "PARENTID='DM102-04'");
////            HttpDataBean httpDataBean = new HttpDataBean();
//            httpDataBean.QueryType = QueryTypeEnum.FJH.getCode();
//            httpDataBean.Data = mGson.toJson(FormatFjhData.formatFjh((CD_TUBERCULOSIS_FOLLOWUP)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
//        } else if (objectList.get(position) instanceof CoronaryHeartDisease) {
//            Log.e(TAG, "冠心病: " );
//            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
//                    "PARENTID='DM04-06'");
////            HttpDataBean httpDataBean = new HttpDataBean();
//            httpDataBean.QueryType = QueryTypeEnum.GXB.getCode();
//            httpDataBean.Data = mGson.toJson(FormatGxbData.formatGxb((CoronaryHeartDisease)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
//        }
//    }

    private void request(int position) {
        if (position >= objectList.size()) return;
        if (objectList.get(position) instanceof CD_HYPERTENSIONFOLLOWUP) {
            Log.e(TAG, "高血压: " );
            String json = AssetUtil.getJson("GxySymptom.json", NovaApplication.getInstance());
            List<BD_DD_INFO> list = GsonUtils.fromJson(json, new TypeToken<List<BD_DD_INFO>>() {}.getType());
            String jsonData = GsonUtils.toJson(FormatGxyData.formatGxyNew((CD_HYPERTENSIONFOLLOWUP)objectList.get(position),list));
            upLoadHttp(jsonData, objectList.get(position), position);
        } else if (objectList.get(position) instanceof CD_DIABETESFOLLOWUP) {
            Log.e(TAG, "糖尿病: " );
            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                    "PARENTID='DM04-03'");
            String jsonData = GsonUtils.toJson(FormatTnbData.formatGxyNew((CD_DIABETESFOLLOWUP)objectList.get(position),listZZs));
            upLoadHttp(jsonData, objectList.get(position), position);
        } else if (objectList.get(position) instanceof CD_MENTALDISEASE_FOLLOWUP) {
            Log.e(TAG, "jsb: " );
//            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
//                    "PARENTID='DM07-01'");
//            httpDataBean.QueryType = QueryTypeEnum.JSB.getCode();
//            httpDataBean.Data = mGson.toJson(FormatJsbData.formatJsb((CD_MENTALDISEASE_FOLLOWUP)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
        } else if (objectList.get(position) instanceof CD_TUBERCULOSIS_FOLLOWUP) {
            Log.e(TAG, "肺结核: " );
//            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
//                    "PARENTID='DM102-04'");
//            httpDataBean.QueryType = QueryTypeEnum.FJH.getCode();
//            httpDataBean.Data = mGson.toJson(FormatFjhData.formatFjh((CD_TUBERCULOSIS_FOLLOWUP)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
        } else if (objectList.get(position) instanceof CoronaryHeartDisease) {
            Log.e(TAG, "冠心病: " );
            List<BD_DD_INFO> listZZs = NovaApplication.fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class,
                    "PARENTID='DM04-06'");
//            httpDataBean.QueryType = QueryTypeEnum.GXB.getCode();
//            httpDataBean.Data = mGson.toJson(FormatGxbData.formatGxb((CoronaryHeartDisease)objectList.get(position),listZZs));
//            upLoadHttp(GsonUtils.toJson(httpDataBean),objectList.get(position),position);
        }
    }

    private void upLoadHttp(String json,Object model,final int position) {
        Log.e(TAG, "upLoadHttp: " + json );
        RxHttp.postJson(HttpNewConstant.getHttpUrlUpLoadData())
                .addAll(json)
                .asClass(HttpResultStrBean.class)
                .subscribe(resultBean -> {
                    if ("0".equals(resultBean.getCode())) {
                        successSize++;
                        updataDb(model);
                    } else {
                        errorSize++;
                        LogUtils.file("随访数据接口上传失败(UpLoadData):" + resultBean.toString());
                        Log.e(TAG, "upLoadHttp: " + resultBean.getResponseMsg() );
                    }
                    sendMsg(START_REQUEST,position);
                }, throwable -> {
                    errorSize++;
                    sendMsg(START_REQUEST,position);
                    LogUtils.file("随访数据接口上传异常:" + throwable.toString());
                });
    }

    private void updataDb(Object object) {
        if (object instanceof CD_HYPERTENSIONFOLLOWUP) {
            Log.e(TAG, "高血压: " );
            CD_HYPERTENSIONFOLLOWUP model = (CD_HYPERTENSIONFOLLOWUP)object;
            model.setIS_UPDATE_NEW("N");
            GxyUpload.upDataGxy(model);
        } else if (object instanceof CD_DIABETESFOLLOWUP) {
            Log.e(TAG, "糖尿病: " );
            CD_DIABETESFOLLOWUP model = (CD_DIABETESFOLLOWUP)object;
            model.setIS_UPDATE_NEW("N");
            TnbUpload.upDataTnb(model);
        } else if (object instanceof CD_MENTALDISEASE_FOLLOWUP) {
            Log.e(TAG, "jsb: " );
            CD_MENTALDISEASE_FOLLOWUP model = (CD_MENTALDISEASE_FOLLOWUP)object;
            model.setIS_UPDATE("N");
            JsbUpload.upDataJsb(model);
        } else if (object instanceof CD_TUBERCULOSIS_FOLLOWUP) {
            Log.e(TAG, "肺结核: " );
            CD_TUBERCULOSIS_FOLLOWUP model = (CD_TUBERCULOSIS_FOLLOWUP)object;
            model.setIS_UPDATE("N");
            FjhUpload.upDataFjh(model);
        } else if (object instanceof CoronaryHeartDisease) {
            Log.e(TAG, "冠心病: " );
            CoronaryHeartDisease model = (CoronaryHeartDisease)object;
            model.setIS_UPDATE("N");
            GxbUpload.upDataGxb(model);
        }
    }

    /**
     * 上传档案数据
     */
    private void upLoadArchivesUpData() {
        totalArchivesSize = 0;
        successArchivesSize = 0;
        errorArchivesSize = 0;
        archiveBaseinfos = fdbmanager.findAllByWhere(ARCHIVE_BASEINFO.class,
                "IS_UPDATE = 'Y'");

        LogUtils.e(archiveBaseinfos.size());
        if (archiveBaseinfos == null || archiveBaseinfos.size() <= 0) {
            ToastUtils.showShort("无数据可上传");
        }else {
            showProgressDialog("档案数据正在上传，请稍候");
            requestArchive(archiveBaseinfos.get(0),0);
        }
    }

    private void requestArchive(ARCHIVE_BASEINFO archiveBaseinfo,int position) {
        HttpDataBean httpDataBean = new HttpDataBean();
        httpDataBean.QueryType = "UserInfo";
        String orgCold = NovaApplication.getDoctorGBcode() + "000000000000";
        httpDataBean.OrgCold = orgCold.substring(0,12);
//        httpDataBean.Data = mGson.toJson(ArchiveFormatData.formatArchive(archiveBaseinfo));
        httpDataBean.Data = ArchiveFormatData.formatArchive(archiveBaseinfo);

        RxHttp.postJson(HttpConstant.getHttpUrlAndroidRegister())
                .addAll(GsonUtils.toJson(httpDataBean))
                .asClass(HttpResultBean.class)
                .subscribe(resultBean -> {
                    if (resultBean.getResponseCode() == 200) {
                        successArchivesSize++;
                        archiveBaseinfo.setIS_UPDATE("N");
                        NovaApplication.fdbmanger.updata(archiveBaseinfo);
                    } else {
                        errorArchivesSize++;
                        LogUtils.file("档案接口上传失败(AndroidRegister):" + resultBean.toString());
                        Log.e(TAG, "upLoadHttp: " + resultBean.getResponseMsg());
                    }
                    sendMsg(UPLOAD_ARCHIVES,position);
                }, throwable -> {
                    errorArchivesSize++;
                    sendMsg(UPLOAD_ARCHIVES,position);
                    LogUtils.file("上传出错了" + throwable.toString());
                });
    }


    /**
     * 上传随访数据
     */
    private void upLoadFollowUpData() {
        totalSize = 0;
        successSize = 0;
        errorSize = 0;
        objectList = new ArrayList<>();
        List<CD_HYPERTENSIONFOLLOWUP> gxyList = NovaApplication.fdbmanger.findAllByWhere(CD_HYPERTENSIONFOLLOWUP.class,
                "IS_UPDATE_NEW = 'Y'");
        List<CD_DIABETESFOLLOWUP> tnbList = NovaApplication.fdbmanger.findAllByWhere(CD_DIABETESFOLLOWUP.class,
                "IS_UPDATE_NEW = 'Y'");
//        List<CD_MENTALDISEASE_FOLLOWUP> jsbList = NovaApplication.fdbmanger.findAllByWhere(CD_MENTALDISEASE_FOLLOWUP.class,
//                "IS_UPDATE = 'Y'");
//        List<CD_TUBERCULOSIS_FOLLOWUP> fjhList = NovaApplication.fdbmanger.findAllByWhere(CD_TUBERCULOSIS_FOLLOWUP.class,
//                "IS_UPDATE = 'Y'");
//        List<CoronaryHeartDisease> gxbList = NovaApplication.fdbmanger.findAllByWhere(CoronaryHeartDisease.class,
//                "IS_UPDATE = 'Y'");
        objectList.addAll(gxyList);
        objectList.addAll(tnbList);
//        objectList.addAll(jsbList);
//        objectList.addAll(fjhList);
//        objectList.addAll(gxbList);
        if (objectList.size() <= 0) {
            ToastUtils.showShort("没有可上传得随访数据");
            return;
        }
        totalSize = objectList.size();
        showProgressDialog("随访数据" + objectList.size() + "条记录,正在上传");
        request(0);
        
    }

    private void sendMsg(int what,int position) {
        Message message = new Message();
        message.what = what;
        position++;
        message.obj = position;
        Log.e(TAG, "sendMsg: " +position);
        if (uploadHandler != null) {
            uploadHandler.sendMessage(message);
        }
    }

    @Override
    public void handleMessage(@NonNull UiMessageUtils.UiMessage localMessage) {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        try {
            UiMessageUtils.getInstance().removeListener(this);
            uploadHandler.removeMessages(START_REQUEST);
            uploadHandler = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //上传档案数据
    private static final int UPLOAD_ARCHIVES_NEW = 1004;
    /**
     * 上传档案到新平台
     */
    private void upLoadArchivesUpDataNew() {
        totalArchivesSizeNew = 0;
        successArchivesSizeNew = 0;
        errorArchivesSizeNew = 0;
        archiveBaseinfosNew = ArchiveUpload.searchDbData();

        LogUtils.e(archiveBaseinfosNew.size());
        if (this.archiveBaseinfosNew == null || this.archiveBaseinfosNew.size() <= 0) {
            ToastUtils.showShort("无数据可上传");
        } else {
            showProgressDialog("档案数据正在上传，请稍候");
            requestArchiveNew(this.archiveBaseinfosNew.get(0),0);
        }
    }

    private void requestArchiveNew(ARCHIVE_BASEINFO archiveBaseinfo,int position) {
        RxHttp.postJson( HttpNewConstant.getHttpNewBaseUrl() + HttpNewConstant.saveOrUpdatePersonal)
                .addAll(GsonUtils.toJson(ArchiveUpload.formatArchive(archiveBaseinfo)))
                .asClass(HttpResultBean.class)
                .subscribe(resultBean -> {
                    LogUtils.e(resultBean);
                    if (resultBean.getCode() == 0) {
                        successArchivesSizeNew ++;
                        ArchiveUpload.upDataTable(archiveBaseinfo);
                    } else {
                        errorArchivesSizeNew ++;
                        LogUtils.file("档案接口上传失败(AndroidRegister):" + resultBean.toString());
                        Log.e(TAG, "upLoadHttp: " + resultBean.getResponseMsg());
                    }
                    sendMsg(UPLOAD_ARCHIVES_NEW,position);
                }, throwable -> {
                    errorArchivesSizeNew ++;
                    sendMsg(UPLOAD_ARCHIVES_NEW,position);
                    LogUtils.file("上传出错了" + throwable.toString());
                });
    }

    //上传体检数据
    private static final int UPLOAD_SBCLDATA_NEW = 1005;

    /**
     * 上传体检数据到新平台
     */
    private void upLoadSbclDataNew() {
        totalSbclDataSizeNew = 0;
        successSbclDataSizeNew = 0;
        errorSbclDataSizeNew = 0;
        sbclDataNewList = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA_NEW.class,
                "IS_UPDATE = 'Y' OR IS_UPDATE IS NULL");

        LogUtils.e(sbclDataNewList.size());
        if (this.sbclDataNewList == null || this.sbclDataNewList.size() <= 0) {
            ToastUtils.showShort("无数据可上传");
        } else {
            showProgressDialog("体检数据正在上传，请稍候");
            requestSbclDataNew(this.sbclDataNewList.get(0),0);
        }
    }

    private void requestSbclDataNew(SBCL_DATA_NEW sbclDataNew, int position) {
        String json = "";
        String url = "";
        if ("AH".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            MeasureBean measureBean = new MeasureBean();
            measureBean.setTemperature(sbclDataNew.getCL_VALUE());
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.savePersonnelTiwen;
        } else if ("BF".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            MeasureBean measureBean = new MeasureBean();
            PwBean pwBean = GsonUtils.fromJson(sbclDataNew.getCL_VALUE(), PwBean.class);
            measureBean.setHdl(pwBean.getHdl() + "");
            measureBean.setLdl(pwBean.getLdl() + "");
            measureBean.setTrig(pwBean.getTg() + "");
            measureBean.setCholesterol(pwBean.getTc() + "");
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.saveK5BloodfatFour;
        } else if ("BG".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            MeasureBean measureBean = new MeasureBean();
            measureBean.setBloodSugar(sbclDataNew.getCL_VALUE());
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.savePersonnelXuetang;
        } else if ("BO".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            PoModel poModel = GsonUtils.fromJson(sbclDataNew.getCL_VALUE(), PoModel.class);
            MeasureBean measureBean = new MeasureBean();
            measureBean.setBloodOxygenSaturation(poModel.getBloodOxygenSaturation());
            measureBean.setHeartRate(poModel.getHeartRate());
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.savePersonnelXueyang;
        } else if ("BP".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            BpModel bpModel = GsonUtils.fromJson(sbclDataNew.getCL_VALUE(), BpModel.class);
            MeasureBean measureBean = new MeasureBean();
            measureBean.setHighpressure(bpModel.getHighpressure());
            measureBean.setLowvoltage(bpModel.getLowvoltage());
            measureBean.setPulse(bpModel.getPulse());
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.savePersonnelXueya;
        } else if ("ECG".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
//            EcgModel ecgModel = GsonUtils.fromJson(sbclDataNew.getCL_VALUE(), EcgModel.class);
//            MeasureBean measureBean = new MeasureBean();
//            measureBean.setIdCard(sbclDataNew.getIDCARD());
//            measureBean.setHr(ecgModel.getHr());
//            measureBean.setEcgResult(ecgModel.getEcgResult());
//            measureBean.setEcgImg(ecgModel.getEcgImg());
//            json = GsonUtils.toJson(measureBean);
//            url = "api/health/personnelxindian/savePersonnelXindian";
        } else if ("FM".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            MeasureBean measureBean = new MeasureBean();
            measureBean.setWeight(sbclDataNew.getCL_VALUE());
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.saveTraPersonnelWeight;
        } else if ("UE".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            UeModel ueModel = GsonUtils.fromJson(sbclDataNew.getCL_VALUE(), UeModel.class);
            MeasureBean measureBean = new MeasureBean();
            measureBean.setUro(ueModel.getUro());
            measureBean.setBld(ueModel.getBld());
            measureBean.setBil(ueModel.getBil());
            measureBean.setKet(ueModel.getKet());
            measureBean.setGlu(ueModel.getGlu());
            measureBean.setPro(ueModel.getPro());
            measureBean.setPh(ueModel.getPh());
            measureBean.setNit(ueModel.getNit());
            measureBean.setLeu(ueModel.getLeu());
            measureBean.setSg(ueModel.getSg());
            measureBean.setVc(ueModel.getVc());
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.saveTraPersonnelNiaoye;
        }

        if ("ECG".equalsIgnoreCase(sbclDataNew.getCL_TYPE())) {
            EcgModel ecgModel = GsonUtils.fromJson(sbclDataNew.getCL_VALUE(), EcgModel.class);
            MeasureBean measureBean = new MeasureBean();
            measureBean.setIdCard(sbclDataNew.getIDCARD());
            measureBean.setHr(ecgModel.getHr());
            measureBean.setEcgResult(ecgModel.getEcgResult());
            measureBean.setEcgImg(ecgModel.getEcgImg());
            measureBean.setTestTime(sbclDataNew.getCL_TIME());
            json = GsonUtils.toJson(measureBean);
            url = HttpNewConstant.savePersonnelXindian;
            if (TextUtils.isEmpty(ecgModel.getEcgImg())) {
                requestHttpSbclDataNew(url, json, sbclDataNew, position);
            } else {

            }
        } else {
            requestHttpSbclDataNew(url, json, sbclDataNew, position);
        }

    }

    private void requestHttpSbclDataNew(String url, String json, SBCL_DATA_NEW sbclDataNew, int position) {
        String baseUrl = HttpNewConstant.getHttpNewBaseUrl();
        RxHttp.postJson(baseUrl + url)
                .addAll(json)
                .asClass(HttpResultStrBean.class)
                .subscribe(resultBean -> {
                    LogUtils.e(resultBean);
                    if ("1".equals(resultBean.getCode())||"0".equals(resultBean.getCode())) {
                        successSbclDataSizeNew ++;
                        sbclDataNew.setIS_UPDATE("N");
                        NovaApplication.fdbmanger.updata(sbclDataNew);
                    } else {
                        errorSbclDataSizeNew ++;
                        LogUtils.file("体检数据上传失败(AndroidRegister):" + resultBean.toString());
                        Log.e(TAG, "upLoadHttp: " + resultBean.getResponseMsg());
                    }
                    sendMsg(UPLOAD_SBCLDATA_NEW,position);
                }, throwable -> {
                    errorSbclDataSizeNew ++;
                    sendMsg(UPLOAD_SBCLDATA_NEW,position);
                    LogUtils.file("上传出错了" + throwable.toString());
                });
    }


   

}
